Up to this point I have thought using the += operator was the same as using something such as n = n + 1. In the below code I return different results when replacing the word_count[word] = word_count[word] + 1 with a += expression. What is the difference?
def word_count_dict(filename):
word_count = {}
opened_file = open(filename, 'r')
for lines in opened_file:
words = lines.split()
for word in words:
word = word.lower()
if not word in word_count:
word_count[word] = 1
else:
word_count[word] = word_count[word] + 1
opened_file.close()
return word_count