Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Functional Python Functional Rules First-Class Functions

Andrew Winkler
Andrew Winkler
37,737 Points

Functional Python: Create a function named apply that should take three arguments: a function and two arguments. apply s

Create a function named apply that should take three arguments: a function and two arguments. apply should return the result of calling the function with the two arguments.

I've been working on this challenge for 30 minutes, but I can't seem to figure it out.

This is probably a really stupid over site on my behalf. I apologize in advance.

functions.py
def apply(func, arg1, arg2):
  return apply(arg1, arg2)

I've also been trying combinations like this:

fuctions.py
def apply(fuct, arg1, arg2):
    return apply (print ('arg1, arg2'))

I just don't understand the formatting. If I had a choice in the matter, I would define each incremental calculation as variables. Maybe I'll just stick to OOP.

1 Answer

Seth Kroger
Seth Kroger
56,403 Points

The variable func is going to be the function to use. Calling the function through the variable is just like calling any other function, only this time you are using the variable's name, not the function's.

def apply(func, arg1, arg2):
  return func(arg1, arg2)
Andrew Winkler
Andrew Winkler
37,737 Points

YESSSS!! This worked. Thank you.