To count number of quadruplets with sum = 0

Paul Rubin http
Fri Mar 16 01:59:52 EDT 2007


"n00m" <n00m at narod.ru> writes:
> h = collections.defaultdict(itertools.repeat(0).next)

Something wrong with 
   h = collections.defaultdict(int)
?????

> for x in e:
>   for y in r:
>     sch += h[-(x + y)]

That scares me a little: I think it makes a new entry in h, for the
cases where -(x+y) is not already in h.  You want:

     for x in e:
       for y in r:
        sch += h.get(-(x+y), 0)



More information about the Python-list mailing list