python - lambda arguments unpack error -
in python 2 code ok:
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 following error occurred:
f = lambda (m, k): m + k ^ syntaxerror: invalid syntax if remove parentheses in lambda expression error occurred:
typeerror: <lambda>() missing 1 required positional argument: 'k' also approach tuple single lambda argument works in python 3, it's not clear (hard reading):
f = lambda args: args[0] + args[1] how can unpack values in right way in python 3?
the removal of tuple unpacking discussed in pep 3113. basically, can't in python 3. under headline transition plan, see "suggested" way of doing final code block:
lambda x_y: x_y[0] + x_y[1]
Comments
Post a Comment