Profiling, sum-comprehension vs reduce

Harold Fellermann dadapapa at googlemail.com
Sat Sep 13 07:06:32 EDT 2008


> doesnt sum first construct the list then sum it?

> def com(lst):
>     return sum(x for x in lst)

You construct a generator over an existing list in your code.
Try sum([x for x in lst]) to see the effect of additional list
construction. And while you're at it, try the simple sum(lst).

Cheers,

- harold -



More information about the Python-list mailing list