I am self studying Python and give myself random tasks to work towards and I am trying to remove the \n from the end of each element in a list that I have created from a text file?
I have seen: How to remove \n from a list element?
However applying this doesn't seem to be working for me and I am not quite sure why? Is anyone able to advise how to strip \n from the end of each element?
word =[]
finalList =[]
#Problem area
dictionary = open ('FILELOCATION\dictionary.txt', 'r')
for line in dictionary.readlines():
word.append([line])
for i in line.split():
finalList[-1].append(i)
#Looping over the list
n = 0
while n < 25:
print (finalList[n])
n += 1