|
|
|
|
|
by Symen
3225 days ago
|
|
But your lambda example would be more clear if collections functions supported chaining. You can add a small comment if you want to be explicit.
This way the code reads linearly, you don't have to wonder why a "square" function and "is_even" function are defined before you see how they are used. # square even numbers
range(11)
.filter(lambda x: not x % 2)
.map(lambda x: x ** 2)
However such a chaining API is not practical in python, because lambda syntax is voluntarily crippled to one expression only. |
|