The second word2 is missing.
>>> d = {}
>>> d["word1"] = 1
>>> d["word2"] = 2
>>> d
{'word1': 1, 'word2': 2}
>>> d["word2"] = 3
>>> d
{'word1': 1, 'word2': 3}
Dictionaries display a specific key for a specific value. If you want a single key to correspond to several values, a list is usually used, and the defaultdict parameter is very convenient:
>>> from collections import defaultdict
>>> d = defaultdict(list)
>>> d["word1"].append(1)
>>> d["word2"].append(2)
>>> d["word2"].append(3)
>>> d
defaultdict(<type 'list'>, {'word1': [1], 'word2': [2, 3]})
source
share