I want to import a text file into my Python file and add each name in each line as a string to a list through a for loop. This is my text file:
A
B
C
D
I tried this:
text_file = open("01.txt", "r")
list1 = text_file.readlines()
list=[]
for name in list1:
list.append(name)
print (list)
But the output is this:
['A\n', 'B\n', 'C\n', 'D']
I want the output to look like this:
['A', 'B', 'C', 'D']
How can I do this?