Jeff Abrahamson on 17 Oct 2004 23:53:03 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[PLUG] python, lambda, map


In the below, I want L=[3,4,5,6] at the end.  Clearly that's not
what's happening.

The problem is that I want to use a map with a lambda form, so I can't
make assignments.

    >>> def foo(x):
    ...     return [x,x+1]
    ...
    >>> foo(3)
    [3, 4]
    >>> foo(3).extend(foo(5))
    >>> L=foo(3).extend(foo(5))
    >>> L
    >>>

I want to write something like this:

    L = map(lambda x: foo(x).extend(foo(x+2)), L)

Any thoughts?

I might have to break down and name this function...

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>    +1 215/837-2287
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B

 A cool book of games, highly worth checking out:
 http://www.amazon.com/exec/obidos/ASIN/1931686963/purple-20

Attachment: signature.asc
Description: Digital signature