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
Open the file first and then process it like this:
with open('text.txt', 'r') as file: content = file.read() h=[w for w in content.split() if w.endswith('os')]