functional programming

Python: Lambda rules

Fredrik Lundh once suggested the following set of rules for refactoring uses of lambda:

  • Write a lambda function.
  • Write a comment explaining what the heck that lambda does.
  • Study the comment for a while, and think of a name that captures the essence of the comment.
  • Convert the lambda to a def statement, using that name.
  • Remove the comment.

I really like these rules, but you’re free to disagree about whether this lambda-free style is better.

from the python docs