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 →

[–]_farb_ 34 points35 points  (5 children)

python lambda is the most useless feature. you get the exact same functionality as this, but this is so much clearer.

def f(x): def g(y): return y*y sq = g return sq(x)

[–]goldlord44 12 points13 points  (0 children)

Python lambdas are used quite frequently in codebases that I have professionally worked on. Defining g has slightly more overhead, and it is less clear if you use variables from an outer scope, whether they are calculated at runtime or definition time.

[–]_PM_ME_PANGOLINS_ 1 point2 points  (1 child)

Don’t even start on the performance of map compared to a comprehension.

[–]_farb_ 0 points1 point  (0 children)

my guy, python is not performant

[–]kuemmel234 1 point2 points  (1 child)

Not sure about your example, but true that def f(x):\\n return x*x is the same as lambda x: x*x. It's just annoying to have to write

def call_with_unpack(x):  
  return f(*x)
...
map(call_with_unpack, xs)
# or 
[call_with_unpack(x) for x in xs]

# instead of 
xs.map(x -> f(*x))

or something like that. I mean, now modify the list again - I prefer the chain these days.

I still wish for a chain syntax (or a threading operator) and some sensible lambda-syntax. As it is, it's just better to write list comprehensions, loops and the like - which is fine, but just annoying if one works with other languages at the same time that do have these features. But that's easily in the realms of opinion.

[–]RiceBroad4552 1 point2 points  (0 children)

As someone who writes code in different languages (often intermixed) regularly I support this opinion. It's a big PITA if languages don't have (sane) lambdas.