Reputation: 6949
I'm trying to convert code from Python 2.x to 3.x from here as and have stumbled over a syntax error with Lambda.
colours.sort(key=lambda (r,g,b): step(r,g,b,8)) # invalid syntax
I assumed that the parentheses before the colon are not needed
colours.sort(key=lambda r,g,b: step(r,g,b,8))
Only that results in a TypeError: () missing 2 required positional arguments: 'g' and 'b'
Can anyone point out where I'm going wrong?
Upvotes: 0
Views: 174
Reputation: 168913
Tuple unpacking in lambda arguments was removed in Python 3.
You'll need to manually index into the tuple.
colours.sort(key=lambda rgb: step(rgb[0],rgb[1],rgb[2],8))
Upvotes: 2