一般方法:
d = {}
for key, value in pairs:
if key not in d:
d[key] = []
d[key].append(value)
使用collections模块中的defaultdict()来实现
from collections import defaultdict
d = defaultdict(list)
for key, value in pairs:
d[key].append(value)
这样用起来更加的优雅,学会了吗?