from collections import defaultdict
data = [(2010, 2), (2009, 4), (1989, 8), (2009, 7)]
d = defaultdict(list)
print (d) # output --> defaultdict(<type 'list'>, {})
for year, month in data:
d[year].append(month)
print (d) # output --> defaultdict(<type 'list'>, {2009: [4, 7], 2010: [2], 1989: [8]})
key = "somekey"
a.setdefault(key, [])
a[key].append(1)
a["abc"] = [1, 2, "bob"]
>>> from collections import defaultdict
>>> data = [(2010, 2), (2009, 4), (1989, 8), (2009, 7)]
>>> d = defaultdict(list)
>>> d
defaultdict(<type 'list'>, {})
>>> for year, month in data:
... d[year].append(month)
...
>>> d
defaultdict(<type 'list'>, {2009: [4, 7], 2010: [2], 1989: [8]})
#Python Dictionary only contain one key : one value pair.
#You can surely have multiple keys having same value
#Example :-
dict = {'a':'value1', 'b':'value2', 'c':'value 3'}
#In above we have a and b key having same values