#!python # encoding: utf-8 import collections def default_factory(): return 'default value' d=collections.defaultdict(default_factory,foo='bar',ok='ok') print 'd:',d print 'foo=>',d['foo'] print 'ok=>',d['ok'] print 'bar=>',d['bar']