dict.get and str.xsplit

marek.rocki at wp.pl marek.rocki at wp.pl
Tue Feb 26 11:46:18 EST 2008


bearophileH... at lycos.com napisał(a):
> 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:

Right, my fault not noticing that. I experimented further with
__missing__ method and with "ask forgiveness" idiom (try... except
KeyError) and they were both noticeably slower. So checking with "in"
may be the most efficient way we have.

Regards,
Marek



More information about the Python-list mailing list