I want to separate the exact words of a text file (text.txt) ending in a certain string by using 'endswith'. The fact is that my variable
h=[w for w in 'text.txt' if w.endswith('os')]
does not give what I want when I call it. On the other hand, if I try naming the open file
f=open('text.txt')
h=[w for w in f if w.endswith('os')]
does not work either. Should I convert the text into a list first?
Comment: I hope this is not duplicate. It is not the same as this former question although close to it.