Python presentations

Alexander Blinne news at blinne.net
Thu Sep 13 18:33:43 EDT 2012


On 13.09.2012 21:01, 88888 Dihedral wrote:
> def powerlist(x, n):
>     # n is a natural number
>      result=[]
>      y=1
>      for i in xrange(n):
>         result.append(y) 
>         y*=x
>      return result # any object in the local function can be returned

def powerlist(x, n):
    result=[1]
    for i in xrange(n-1):
        result.append(result[-1]*x)
    return result

def powerlist(x,n):
    if n==1:
        return [1]
    p = powerlist(x,n-1)
    return p + [p[-1]*x]




More information about the Python-list mailing list