1 from collections import defaultdict
2 data = [(2010, 2), (2009, 4), (1989, 8), (2009, 7)]
3 d = defaultdict(list)
4print (d) # output --> defaultdict(<type 'list'>, {})
5 for year, month in data:
6 d[year].append(month)
7print (d) # output --> defaultdict(<type 'list'>, {2009: [4, 7], 2010: [2], 1989: [8]})