Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to separate words separated by tabs in pythond

My file look that:

abc 1
bca 2

How to get texts(abc and bca) and append to array and get numbers and append to another array?
I made this:

plik = open("testcase.txt", "r")
imie = []
dlugosc = []
for line in plik:
    for word in line.split():
        imie.append(word)

Now when i print "imie" that shows everythinkg.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can try this to check digit

a_string = "abc 1 bca 2"
numbers = []
for word in a_string.split():
    if word.isdigit():
        numbers.append(int(word))

print(numbers)

OUTPUT : [1,2]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading