Summing a 2D list

Karsten Heymann karsten.heymann at blue-cable.net
Fri Jun 13 11:25:54 EDT 2008


Paddy <paddy3118 at googlemail.com> writes:
> How does your solution fare against the defaultdict solution of:
>
> d = collections.defaultdict(int)
> for u,s in zip(users,score): d[u] += s

list:         0.931s
dict + "in":  1.495s
defaultdict : 1.991s
dict + "if":  ~2s
dict + "try": ~4s

I've posted the (very rough) code to dpaste:

http://dpaste.com/hold/56468/

Yours
Karsten



More information about the Python-list mailing list