def files_to_dict(folder_name):
list_of_files = os.listdir("./"+folder_name) #read file names of current dir in list
newDict=dict()
for year in (list_of_files):
if(year!=".ipynb_checkpoints"):
ofile = open("./"+folder_name+"/"+year,"r")
data = ofile.read().split(',')
return data
I am trying to remove all delimiters while reading file into a list, including '\n'. I have tried using the above method but it gives the output like
'Emma', 'F', '20799\nOlivia', 'F', '19674\nSophia', 'F', '18490\nIsabella', 'F', '16950\nAva',
The list goes on will the same pattern. I want to remove the '\n' from the middle of the string in a list. I want to find an efficient solution which doesn't involve running a loop on the entire list again and removing the '\n' from each index.
Expexted Output:
'Emma', 'F', '20799', 'Olivia', 'F', '19674', 'Sophia', 'F', '18490', 'Isabella', 'F', '16950', 'Ava',