Reputation: 30755
Is there any difference between the two?
1. a = b.map(lambda (x,y): (y,x))
2. a = b.map(lambda x: (x[1], x[0]))
For those who work in Scala, I think it would be something like this.
1. a = b.map((x,y) => (y,x))
2. a = b.map(x => (x._2, x._1))
Upvotes: 2
Views: 194
Reputation:
In Python 2 those are identical.
The difference in Python 3 is that the first one is a syntax error and the second one isn't.
The difference in Scala is that the first one is a binary function and the second one is a unary function taking a tuple. If you want to pattern match you have to pass a partial function, like this: y.map{ case (x,y) => (y,x) }
.
Upvotes: 3