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 i
Splitting the seperate words into a list (assuming they are seperated by spaces)
f = open('text.txt').read().split(' ')
Then to get a list of the words ending in "os", like you had:
h=[w for w in f if w.endswith('os')]