Statement (un)equality
Erik Max Francis
max at alcyone.com
Fri Feb 20 05:50:19 EST 2004
Adam Przybyla wrote:
> >>> [[y,x] for x,y in [1,2],[3,4]]
> [[2, 1], [4, 3]]
> >>> map(lambda x,y: [y,x], [1,2],[3,4])
> [[3, 1], [4, 2]]
> >>>
> Why there is a difference? How to make the same thing like in map
> statement?
Because the same things aren't happening here, despite their outward
similarity. For the second case to be equivalent to the first, you
really meant:
>>> map(lambda x: [x[1], x[0]], [[1, 2], [3, 4]])
[[2, 1], [4, 3]]
You can pass multiple sequences to map, and that interleaves the
results:
>>> map(lambda x, y, z: (x, y, z), [1, 2], [3, 4], [5, 6])
[(1, 3, 5), (2, 4, 6)]
--
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ Come not between the dragon and his wrath.
-- King Lear (Act I, Scene I)
More information about the Python-list
mailing list