📅  最后修改于: 2022-03-11 14:46:45.891000             🧑  作者: Mango
from collections import defaultdict
data = [(2010, 2), (2009, 4), (1989, 8), (2009, 7)]
d = defaultdict(list)
print (d) # output --> defaultdict(, {})
for year, month in data:
d[year].append(month)
print (d) # output --> defaultdict(, {2009: [4, 7], 2010: [2], 1989: [8]})