Apr-22-2020, 02:39 PM
I may be really missing something, but isn't this all you need?
Are you expecting multiple lines to "Adres"? If so do you want all the words in one list, or do you want each a list of words for each matching line? If the second, replace "adressatiri += line.split()" with "adressatiri.append(line.split())
fhand=open("arb1.txt") adressatiri=[] for line in fhand: if line.startswith("Adres"): adressatiri += line.split() fhand.close() print(adressatiri)This program finds lines that start with "Adres", splits the line into words, and appends the words to the list adressatiri.
Are you expecting multiple lines to "Adres"? If so do you want all the words in one list, or do you want each a list of words for each matching line? If the second, replace "adressatiri += line.split()" with "adressatiri.append(line.split())