+ 1
def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10))
to my best understanding let's rename our functions as def a(b,c) --- which is the same thing as def apply_twice(func,arg) now the second function will be def p(k) which is the same this as def add_five(x) now let's bring our renamed functions out def a(b,c): return b(b(c)) def p(k): return k + 5 print(a(p,10)) our b will change to p now p(p(c)) c=10 p=k + 5 solve the inner parenthesis which is p(p(10)) anywhere you find "k" replace it with 10 p(k+5) p(10+5) p(15) now our "k" has changed to 15, now solve the last p, we have: p(15) k+5 (input 15 as k) 15 + 5 20
4 odpowiedzi
+ 3
Sooo, what's the question?
+ 2
Nice detail break down, but for code readability sake, "apply_twice" and "add_five" serves better because they give better understanding of what they do opposed to "a" or "p" : )
+ 2
Tijani Julius Best I didn't see any question either, I know that sample came with Python lesson, but Hatsy was asking whether if you have a question, because all I see up there was you explaining your idea to change function names, and that is still not a question.
Remember what this forum purpose though, to ask questions related to coding : )
* Edit: I'm outta here *
+ 1
that's the question at top