how to read a text file to a list in python code example
Example 1: how to put a text file into a list python
# name.txt
david
mary
john
with open('names.txt', 'r') as f:
myNames = [line.strip() for line in f]
# Result
['david','mary','john']
Example 2: how to read from a file into a list in python
f = open(filename, "r")
listItems = f.read().splitlines()