a=[ lambda t: t**n for n in range(4) ]

Larry Bates lbates at syscononline.com
Fri Apr 22 18:00:28 EDT 2005


Please post a description of what you are trying to
accomplish instead of asking us to take your possible
solution and try to figure out what the problem was.

You can do:

def foo(t, r):
    return [t**n for n in range(r)]

a=foo(2, 4)
a
[1, 2, 4, 8]

a=foo(3,6)
a
[1, 3, 9, 27, 81, 243]

but I don't really know what you want.

Larry


mehmetmutigozel at gmail.com wrote:
> I was thinking about something like the following;
> 
> 
>>>>a=[ t**n for n in range(4) ]
> 
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> NameError: name 't' is not defined
> 
> 
> or
> 
> 
>>>>a=[ lambda t: t**n for n in range(4) ]
>>>>t=2
>>>>a
> 
> [<function <lambda> at 0x403dcc6c>, <function <lambda> at 0x403dcca4>,
> <function <lambda> at 0x403dccdc>, <function <lambda> at 0x403dcd14>]
> 
>>>>t=3
>>>>a
> 
> [<function <lambda> at 0x403dcc6c>, <function <lambda> at 0x403dcca4>,
> <function <lambda> at 0x403dccdc>, <function <lambda> at 0x403dcd14>]
> 
> 
> is something like that possible? Will you give me advice about that?
> 



More information about the Python-list mailing list