Python Forum
I need help with a Kata - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: I need help with a Kata (/thread-19647.html)



I need help with a Kata - Jaccobtw - Jul-08-2019

https://www.codewars.com/kata/change-your-points-of-view/train/python

I don't understand how to pass a callable value into the functions fst and snd. Thanks for your help


RE: I need help with a Kata - nilamo - Jul-08-2019

A callable object is a first-class citizen, which means it can be used just like any other object, such as an int. Passing a callable object to a function is then done the same way as with any other object:
def my_func():
    print("called")

def consume(obj):
    if callable(obj):
        return obj()
    return obj

# pass an int
consume(42)

# pass a callable object
consume(my_func)



RE: I need help with a Kata - Jaccobtw - Jul-09-2019

IS there a way I can write a function that returns a value and is callable?
def point(a, b):
    f():
        return a, b
    return f
This is callable but doesn't return a or b
def point(a, b):
        return a, b
This returns a and b but is not callable

I need a function that can do both




RE: I need help with a Kata - nilamo - Jul-10-2019

(Jul-09-2019, 12:00 AM)Jaccobtw Wrote: This is callable but doesn't return a or b
def point(a, b):
        return a, b

That IS callable, and DOES return both a and b.