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 trialSahar Nasiri
7,454 PointsThe else part
We already have this statement above why do we write it again? I mean this part:
if y is not None and z is not None:
return f(x, y, z)
We check this statement here and again we write it here:
return lambda y, z=None: (
f(x, y, z) if (y is not None and z is not None)
else (lambda z: f(x, y, z)))
1 Answer
Haydar Al-Rikabi
5,971 PointsYou are right. The whole thing can be shortened as follows:
def curried_f(x, y=None, z=None):
def f(x, y, z):
return x**3 + y**2 + z
if y is not None and z is not None:
return f(x, y, z)
return lambda y, z=None: lambda z: f(x,y,z)
Brady Huang
16,360 PointsBrady Huang
16,360 PointsHaving the same question as mine, the
f(x, y, z) if (y is not None and z is not None)
is redundant.