defaultdict(): 默认类型为字典,继承了字典的方法
import collections
dic = collections.defaultdict()
dic['k1'] = 'hello'
print(dic)
dic1 = collections.defaultdict(list)
dic1['k2'].append(34)
dic1['k2'].append(3)
print(dic1)
结果:
defaultdict(None, {'k1': 'hello'})
defaultdict(<class 'list'>, {'k2': [34,3]})