Stack Overflow Asked by Nataku62 on December 9, 2020
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 ('FILELOCATIONdictionary.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
final_list = []
with open("accounts.txt","r") as my_file:
first_list = my_file.readlines()
for i in first_list:
final_list.append(i.strip())
change it to suit your needs, this removes any n
.
Answered by Evan Dilkes on December 9, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP