Why do parentheses in a lambda function cause syntax error on Python 3? [duplicate]

Using parentheses to unpack the arguments in a lambda is not allowed in Python3. See PEP 3113 for the reason why.

lambda (k, v): (-v, k)

Instead use:

lambda kv: (-kv[1], kv[0])

Leave a Comment