Python presentations

Chris Angelico rosuav at gmail.com
Sun Sep 16 12:19:58 EDT 2012


On Mon, Sep 17, 2012 at 2:13 AM, Alexander Blinne <news at blinne.net> wrote:
> def powerlist3(x,n):
>   return [x**i for i in xrange(n)]
>
> for really big n powerlist3 always takes very much time :)

I would reiterate that a really big n is a really unusual use case for
a function like this, except that... I frankly can't think of *any*
use case for it!! But for many many applications, the simplicity and
readability of a list comp instead of a function is usually going to
outweigh the performance differences.

However, it doesn't surprise me that individually raising a number to
successive powers is slower than iterative multiplication, assuming
you can't massively optimize eg with powers of 2 and bit shifts.

ChrisA



More information about the Python-list mailing list