How do I read every line of a file in Python and store each line as an element in a list?
I want to read the file line by line and append each line to the end of the list.
To read a file line-by-line into a list you can use the below-mentioned code:-
with open(filename) as f:content = f.readlines() content = [x.strip() for x in content]
with open(filename) as f:
content = f.readlines()
content = [x.strip() for x in content]