1

The easiest way to show this is an example:

def hat(a, b):
    return a+b

def cat(c, d):
    return c % 2, d % 2 

If I type cat(4,5) I properly get (0,1). However if I try hat(cat(4,5)) instead of getting 1, I get an error saying hat needs more values. In my real function I am dealing with a lot more than 2 arguments, so what is the proper way to fix this

0

1 Answer 1

8

The cat function actually returns a tuple, when used as an argument to hat, it can only match the tuple against the first argument a. You need to expand the tuple into multiple arguments.

Try a call like:

hat(*cat(4,5))

The * will expand the tuple and bind against all the arguments.

Sign up to request clarification or add additional context in comments.

Comments

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.