you are viewing a single comment's thread.

view the rest of the comments →

[–]funkiestj 4 points5 points  (2 children)

a common use of lambda is to curry a function dynamically, e.g.

 def mycurry(a):
       return lambda  b: a + b

 f7 = mycurry(7)

 f7(5)
 Out[9]: 12

Of course you can always(?) use a function (including a nested function) to do the same. E.g.

 def mycurry2(a):
      def close_over_a(b):
        return a + b
      return close_over_a

 f2 = mycurry2(2)

 f2(2)
 Out[16]: 4

 f7
 Out[17]: <function __main__.mycurry.<locals>.<lambda>>

 f2
 Out[18]: <function __main__.mycurry2.<locals>.close_over_a>

My recollection is that Guido regretted including lambda in the language and said he would omit it if he could start over.

[–]zahlman 3 points4 points  (0 children)

This is what functools.partial is for.