In Python 2, this code is fine:
f = lambda (m, k): m + k m = [1,2,3,4] k = [5,6,7,8] print(map(f, zip(m, k)))
but in Python 3, an error occurred:
f = lambda (m, k): m + k ^ SyntaxError: invalid syntax
If I remove the parentheses in the lambda expression, another error occurs:
TypeError: <lambda>() missing 1 required positional argument: 'k'
Also a tuple approach, since a single lambda argument works in Python 3, but it is not clear (hard to read):
f = lambda args: args[0] + args[1]
How can I decompress values โโcorrectly in Python 3?
source share