Python presentations
Alexander Blinne
news at blinne.net
Fri Sep 14 07:47:57 EDT 2012
On 14.09.2012 00:38, Chris Angelico wrote:
> On Fri, Sep 14, 2012 at 8:33 AM, Alexander Blinne <news at 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)
More information about the Python-list
mailing list