sqrt() argument after * must be a sequence
Question: First of all, I'm super new to python and I actually search for my problem but
the examples were to heavy to understand.

Here is my homework; I need a function which takes two functions as an
argument and returns if the results of the two functions are same or not?
Basically, it will give either TRUE of FALSE.

For that I wrote:

    
    
    def f(x,y,z):
        k=x(*z)
        l=y(*z)
        return k == l
    

The previos code I wrote for single function was working but when I modified
it for two function as above, it gives an error as following :

    
    
    import math
    >>> f(math.sqrt,math.cos,5)
    
    Traceback (most recent call last):
      File "<pyshell#56>", line 1, in <module>
        f(math.sqrt,math.cos,5)
      File "D:/Users/karabulut-ug/Desktop/yalanmakinesi.py", line 2, in f
        k=x(*z)
    TypeError: sqrt() argument after * must be a sequence
    >>> 
    

I could not figured it out since the error giving function is normally does
not take a sequence. So I dont think it makes a sense :) Any help is
appreciated.. Thanks :)


Answer: `z` is just a single number, but the `*` argument expansion syntax requires
that you pass in a sequence (like a `list`, `tuple` or `str`, for example).

Either _remove_ the `*` (and make your function work for just single
arguments), or use `*z` in the function signature to make `z` a tuple of 0 or
more captured arguments:

    
    
    def f(x, y, z):
        k = x(z)
        l = y(z)
        return k == l
    

or

    
    
    def f(x, y, *z):
        k = x(*z)
        l = y(*z)
        return k == l
    

The latter now works for functions with more than one argument too:

    
    
    f(math.pow, math.log, 10, 10)
    

If you added a `**kw` argument to the signature, then keyword arguments could
be handled too:

    
    
    def f(x, y, *args, **kwargs):
        k = x(*args, **kwargs)
        l = y(*args, **kwargs)
        return k == l
    

Here I renamed `z` to `args` to better reflect its purpose.

