>>>
>>>def sqr(x): return x*x
>>>def sqr(x): return x*x
>>>def cube(x): return x*x*x
>>>sqr
>>>a = [sqr, cube]
>>>a[0](2)
>>>def compose(f, g): return f(g(x))
>>>a[0](2)
>>>def compose(f, g): return f(g(x))
>>>compose(sq r, cube, 2)
>>>
but i get:
>>compose(sqr , cube, 2)
File "<pyshell#5 6>", line 1, in <module>
compose(sqr, cube, 2)
TypeError: compose() takes exactly 2 arguments (3 given)
this:
>>def compose(f, g, x): return f(g(x))
>>compose(sqr , cube, 2)
>>compose(sqr , cube, 2)
works though
.. so just a mistake on his part? but it looks like he just copied his
shell...has there been a change since 2004 inr egards to how you can
pass functions as arguments to functions??
Comment