Statement (un)equality

Jonas Galvez jonas at jonasgalvez.com
Fri Feb 20 11:48:18 CET 2004


> [Adam Przybyla]
> >>> [[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]]

>>> def test(a,b):
        print "a:", a, "b:", b
        return [b,a]
>>> map(test, [1,2], [3,4])
a: 1 b: 3
a: 2 b: 4
[[3, 1], [4, 2]]
>>> [test(a, b) for a, b in [1,2], [3,4]]
a: 1 b: 2
a: 3 b: 4
[[2, 1], [4, 3]]
>>> [test(a, b) for a, b in zip([1,2], [3,4])]
a: 1 b: 3
a: 2 b: 4
[[3, 1], [4, 2]]



Jonas








More information about the Python-list mailing list