squared functions--most Pythonic way?

Sean 'Shaleh' Perry shalehperry at attbi.com
Thu Jun 27 21:45:24 CEST 2002

> functional programming:
>     # with an internal named function
>     def fsquare(f):
>         def f2(x):
>             return f(x)**2
>         return f2

this seems to be the most pythonic (lambda is not the preferred approach

Of course someone will mention taking this to the next step with a compose()
function which take f(x) and g(x).

More information about the Python-list mailing list