Semi-Newbie needs a little help

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jul 6 23:51:07 EDT 2009


En Mon, 06 Jul 2009 19:49:41 -0300, MRAB <python at mrabarnett.plus.com>
escribió:
> Chris Rebert wrote:

>>  from collections import defaultdict
>>  counts = defaultdict(lambda: 0)
>>
> Better is:
> counts = defaultdict(int)

For speed? This is even faster:
zerogen = itertools.repeat(0).next
counts = defaultdict(zerogen)

-- 
Gabriel Genellina




More information about the Python-list mailing list