It's not a matter of absolute need; it's a matter of shortening functions. For example, say I have a list of username and number of posts:
users = [["user1", 500], ["n00b", 15], ["thebestuser", 177]]
I want to sort the users according to number of posts. The sorted() function takes a parameter key=, you can do it this way without lambda: def get_users_by_posts():
def get_post_count(user):
return user[1]
return sorted(users, key=get_post_count)
The lambda implementation is a one-liner: def get_users_by_posts():
return sorted(users, key=lambda u : u[1])
Well, technically a twoliner, unless you use lambda more aggressively than most people: get_users_by_posts = lambda : sorted(users, key=lambda u : u[1])
In general, you can always expand your lambda's into def's, but it can make your code longer and pollute the code with named functions that do trivial things.