> a = [1, 2, 3]
[ 1, 2, 3 ]
> a.map(i => i+10)
[ 11, 12, 13 ]


>>> a = [1, 2, 3]
>>> [j for j in map(lambda i: i+10, a)]
[11, 12, 13]



@0 I'd suggest writing the code like this:

>>> a = [1, 2, 3]
>>> list(map(lambda i: i+10, a))
[11, 12, 13]
>>> # or
>>> [i+10 for i in a]
[11, 12, 13]

· · Web · 1 · 0 · 1

@masipcat @0 the second one is more pythonic - list comphrehensions rule!


I remain distinctly unconvinced by Python. Then again, as a #Lisp programmer (back in the 80s when it was still a thing) nearly every other language since has seemed a step backwards.


@0 @Wraptile


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]
[11, 13]

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. 😒


@masipcat @Wraptile

My impression is that #Python is popular because, like #Basic back in the day, is easy to get started with and there are lots of libraries and support resources for it. Possibly easy to embed too. But make no mistake: it's the #VisualBasic of our days.

@0 @masipcat lol, seems like you have no idea what you are talking about.

if your "inline function" is too big in python then it should NOT be an inline function, simple as that. It's opinionated language and that's a good thing.

Try `import this`

@0 @masipcat you certainly seem to have some bias against python. Your own example is clearly gimped and the fact that you think Javascript, language so notoriously badly design that has a thousand different flavors, is better designed than Python is really peculiar to say the least.

Sign in to participate in the conversation

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!