I have some text files (just using two here), and I want to read them in to Python and manipulate them. I'm trying to store lists of strings (one string for each word, one list each file).
My code currently looks like this: (files are named m1.txt and m2.txt)
dict={'m1':[],'m2':[]}
for k in files:
with open(k,'r') as f:
for line in f:
for word in line.split():
for i in range (1,3):
dict['m'+str(i)].append(word)
This code ends up combining the words in both text files instead of giving me the words for each file separately. Ultimately I want to read lots of files so any help on how to separate them out would be much appreciated!
appending words theoretically from m1.txt intodict['m2']dictas a variable