dict.get and str.xsplit

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Feb 26 10:54:18 EST 2008


marek.ro... at wp.pl:
> As for the original prooblem, why not use
> defaultdict? I think it's the most idiomatic way to achieve what we
> want. And also the fastest one, according to my quick-and-dirty tests:

It adds the new keys, I can't accept that:

>>> from collections import defaultdict as dd
>>> adict = {1:2, 3:4}
>>> addict = dd(lambda: None, adict)
>>> r = addict[10]
>>> addict
defaultdict(<function <lambda> at 0x008E6FB0>, {1: 2, 10: None, 3: 4})

Bye,
bearophile



More information about the Python-list mailing list