optimizing large dictionaries
Scott David Daniels
Scott.Daniels at Acm.Org
Fri Jan 16 02:36:08 EST 2009
Paul Rubin wrote:
> Per Freem <perfreem at yahoo.com> writes:
>> 2] is there an easy way to have nested defaultdicts? ie i want to say
>> that my_dict = defaultdict(defaultdict(int)) -- to reflect the fact
>> that my_dict is a dictionary, whose values are dictionary that map to
>> ints. but that syntax is not valid.
>
> my_dict = defaultdict(lambda: defaultdict(int))
or
my_dict = defaultdict(functools.partial(defaultdict, int))
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list