0

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?

1 Answer 1

2

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)) 
Sign up to request clarification or add additional context in comments.

1 Comment

Yes. That makes sense now. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.