Maybe the JS map() with an arrow function looks better in that case, but IMO list-comprehensions are more powerful and easier to read.
You can create a list/set/dict from any iterable (not necessary a list object!). Also, you can filter while iterating:
>>> [i+10 for i in a if i % 2 == 1]
For me it's easier to remember how it works a list-comprehension than filter. I never remember if `filter()` filters the values when the lambda returns true or false...
The actual code I was looking at wasn't quite so trivial, requiring the use of a function for the transformation.
The transform was just about possible to write inline in Python in that case, but I'm seeing one-shot functions way too often with Python just because of its brain-dead, form-over-function syntax.
And we will not talk about package management. 😒
The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!