To count number of quadruplets with sum = 0

Steven Bethard steven.bethard at
Fri Mar 16 16:37:28 CET 2007

Marc 'BlackJack' Rintsch wrote:
> In <7x6491k9t3.fsf at>, Paul Rubin wrote:
>> "n00m" <n00m at> writes:
>>> h = collections.defaultdict(itertools.repeat(0).next)
>> Something wrong with 
>>    h = collections.defaultdict(int)
>> ?????
> According to a post by Raymond Hettinger it's faster to use that iterator
> instead of `int`.

Yep. It's because the .next() method takes no arguments, while int() 
takes varargs because you can do::

     int('2', 8)

Calling a no-args function is substantially faster than calling a 
varargs function.


More information about the Python-list mailing list