how do you convert a text file into a list?

you can use the strip and readlines methods for this:

someone can tell/figure
a/the squeaky wheel gets the grease/oil
accounts for (someone or something)

(make sure to open the file correctly)

with open('words.txt', "r") as f:
    text = [line.strip() for line in f] #or rstrip()
print(text)

output:

['someone can tell/figure', 'a/the squeaky wheel gets the grease/oil', 'accounts for (someone or something)']

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top