This is the code:
word_count = {}
with open(file, "r") as fi:
for line in fi:
words = line.split()
for word in words:
word = word.lower()
if word not in word_count:
word_count[word] = 0
word_count[word] += 1
print(word_count)
Output:
{'thou': 2, 'ancient,': 1, 'free': 1}
I want to somehow get access to the numbers 2,1 and 1 so I can get the average usage of the words in my text file. So my question is how do I do it?
I've tried to use the dictionary somehow to add up the numbers in the dictionary but in it, I have both the words and the numbers so I get "TypeError: 'int' object is not iterable".