Which is faster?
fredrik at pythonware.com
Sat Aug 30 07:57:07 CEST 2008
> For a big nbr of it might matter?
> Is av_grade O(n*2) and the first O(n) when it comes to adding or is
> "sum x for x in y" just traversing the list ones, accumulating the
> values, it doesnt first build the list and then travese it for sum?
sum() doesn't build a list, but even if it would do that, it'd still be
O(n) -- looping over an array twice doesn't change the time complexity.
to find out which one's actually faster, benchmark them.
More information about the Python-list