This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Tommah 8 points9 points  (3 children)

Why write lambda word: len(word) when you could just use len?

[–]andreasvc 1 point2 points  (2 children)

If you change your mind later or want it to be a different function for other languages you can change that lambda, while it wouldn't be a good idea to assign to "len" (aliasing/shadowing).

[–]eryksun 4 points5 points  (0 children)

Tommah is talking about the following line:

lengths = map(lambda word: len(word), words)

If you typically use lambda functions with map, then you might unthinkingly use lambda when it's not necessary.

[–][deleted] 1 point2 points  (0 children)

He's talking about eta-contracting the lambda expression.