7 ms·
Huh? This seems like it works fine in python? filter(lambda x: x < 10, map(lambda x: x * x, [1, 2, 3, 4])) But even for more complicated logic, it also d
by notdonspaulding 5y ago
Huh? This seems like it works fine in python?
filter(lambda x: x < 10, map(lambda x: x * x, [1, 2, 3, 4]))
But even for more complicated logic, it also doesn't seem like it's that burdensome to just throw a name on the lambda:
def square(x):
return x * x
def less_than_ten(x):
return x < 10
filter(less_than_ten, map(square, [1, 2, 3, 4]))
Which I find to be more readable/maintainable.
That's probably the most underrated feature of python. Decisions about how the language should function like this which seem "restrictive" from one perspective, and yet force you down the avenue of good decision-making for readability/maintainability. Sure, it's possible to write terrible python, but you're generally cutting against the grain to do it.
- IshKebab 5y agoYes you can do simple examples like the one I gave, but when it gets more complex you have to do what you did and name the functions, which is pretty horrible when they're just one-offs. It also makes the code read in a weird order.