squared functions--most Pythonic way?

Luigi Ballabio ballabio at mac.com
Sat Jun 29 07:42:31 EDT 2002


In article <afiqfr$9re$1 at panix1.panix.com>, aahz at pythoncraft.com (Aahz) 
wrote:

> In article <ballabio-E54F22.21380327062002 at newssrv.fastweb.it>,
> Luigi Ballabio  <ballabio at mac.com> wrote:
> >
> >      suppose we want to define a function which, given f(x), returns 
> >its square. There are a number of ways which come to mind, such as:
> >
> > (snip)
> 
> I'm sensing an ill-defined spec here.  To me, your English sentence
> implies that what's wanted is
> 
>     def fsquare(f, x):
>         return f(x)**2
> 
> but both of your examples define closures of some sort.

The error was in the english. What I meant was:
"a function which takes a function f and returns another function g such 
that g(x) = f(x)**2"

And by the way, thanks to all who answered...

Bye,
      Luigi



More information about the Python-list mailing list