Do I need a nested lambda to do this?

raoul raoul.daruwala at gmail.com
Mon Apr 25 19:34:21 EDT 2005


I can't figure this one out. Trying to be unnecessarily functional I
suspect.

I have the following lists.

vals = [1.000,2.344,4.2342]
tab = [((0,1),(0,3),(0,4)),
       ((2,2),(3,0),(3,9)),
       ((3,4),(6,3),(7,1))]

I'm trying to create a one liner using map/reduce/lambda/zip(* etc to
do replace the first element of each pair in each row by the the values
in vals as follows:

tab = [((1.000,1),(1.000,3),(1.000,4)),
       ((2.344,2),(2.344,0),(2.344,9)),
       ((4.2342,4),(4.2342,3),(4.2342,1))]

I'm pretty sure there's a oneline way to do this. Naturally, one could
loop mindlessly but this is my self-imposed programming challenge for
the day and I'm not feeling much love from my python.




More information about the Python-list mailing list