Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Functional Python Functional Rules First-Class Functions

Andrew Winkler
Andrew Winkler
37,739 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,413 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,739 Points

YESSSS!! This worked. Thank you.