0 votes
1 view
in Python by (47.8k points)

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.

1 Answer

0 votes
by (107k points)

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]

Related questions

+1 vote
1 answer
0 votes
1 answer
asked Jul 26, 2019 in Python by selena (1.6k points)
0 votes
1 answer
asked Sep 25, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...