Lambda Functions (fwd)

Tim Peters tim_one at
Tue Aug 10 23:23:59 EDT 1999

> ...
> Python allows the use of lambda functions, small anonymous functions
> that can speed up processing because they are effectively inlined,

lambdas don't speed up anything in Python; they're not inlined (let alone
effectively <wink>); they're exactly as expensive as "def" functions to
invoke; they're often a little more expensive than "def" functions in
practice because of repeated construction, e.g.

def f(x):
    return x+1

for i in range(1000):
    print f(i)

constructs the function object f only once, while

for i in range(1000):
    print (lambda x: x+1)(i)

constructs an anonymous function object 1000 times.

    scratched-into-your-chest-ly y'rs  - tim

More information about the Python-list mailing list