On 14.09.2012 00:38, Chris Angelico wrote: > On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne <n...@blinne.net> wrote: >> def powerlist(x,n): >> if n==1: >> return [1] >> p = powerlist(x,n-1) >> return p + [p[-1]*x] > > Eh, much simpler. > > def powerlist(x,n): > return [x*i for i in xrange(n-1)]
I suppose you meant: def powerlist(x,n): return [x**i for i in xrange(n-1)] But this is less efficient, because it needs more multiplications (see Horner's method) -- http://mail.python.org/mailman/listinfo/python-list