Strip n from list created from txt file

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():
    for i in line.split():

#Looping over the list
n = 0
while n < 25:
    print (finalList[n])
    n += 1

One Answer

final_list = []
with open("accounts.txt","r") as my_file:
    first_list = my_file.readlines() 
    for i in first_list: 

change it to suit your needs, this removes any n.

Answered by Evan Dilkes on December 9, 2020

Add your own answers!

Related Questions

What is the purpose of session.endConversation()

1  Asked on January 23, 2021 by flea


To convert not null datetime into null. c#

1  Asked on January 23, 2021 by mashail-furqan


Updating Values in ArrayList in Java

2  Asked on January 23, 2021 by billy-dan


C++: Can a Template be friend of a Class?

1  Asked on January 23, 2021 by ali-rojas


Retrieving image from database and showing it Laravel

5  Asked on January 22, 2021 by parsa_237


f-strings works on python IDLE but not on Sublime Text

3  Asked on January 22, 2021 by david-jiang


SQL Select List mulitple values with case then

2  Asked on January 22, 2021 by user14082433


setState does not update TextFormField when use initialValue

1  Asked on January 22, 2021 by wondertalik


IndexError: Index out of range Python Error

1  Asked on January 22, 2021 by user13669275


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP