If I have d=dict(zip(range(1,10),range(50,61))) how can I build a collections.defaultdict out of the dict?
d=dict(zip(range(1,10),range(50,61)))
collections.defaultdict
dict
The only argument
You can construct a defaultdict from dict, by passing the dict as the second argument.
from collections import defaultdict d1 = {'foo': 17} d2 = defaultdict(int, d1) print(d2['foo']) ## should print 17 print(d2['bar']) ## should print 1 (default int val )