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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s