So I'm reading in a txt file in python and want to get a list of all the words in the file. I am doing so by this method.
def parse_in(file_location, input_name):
all_words = []
with open(file_location + input_name,'r') as f:
for line in f:
for word in line.split():
all_words += word
f.close
return all_words
Instead of all_words returning actual words it returns a list of single characters like ['A', 'B', 'C'] and so on.
But when debugging I can see that the variable word is an actual word and not just characters. Where am I going wrong here?
f.closedoes nothing. Your adding a sequence (string) to another sequence (a list), so you get a sequence thats the combination of both sequences. Uselist.append.