defaultdict pythin code example
Example 1: python defaultdict
>>> from collections import defaultdict
>>> ice_cream = defaultdict(lambda: 'Vanilla')
>>>
>>> ice_cream = defaultdict(lambda: 'Vanilla')
>>> ice_cream['Sarah'] = 'Chunky Monkey'
>>> ice_cream['Abdul'] = 'Butter Pecan'
>>> print ice_cream['Sarah']
Chunky Monkey
>>> print ice_cream['Joe']
Vanilla
>>>
Example 2: defaultdict initialize keys
d = {'a' : 1, 'b' : 2, 'c' : 3}
default_d = defaultdict(list, **d)
d = defaultdict(list,{ k:[] for k in ('a','b','c') })