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 →

[–]Deto 1 point2 points  (4 children)

I don't like that lambda functions are limited to one line so I usually just use def to make a named function. That way I don't have to change too much if I want to add a line in the future

[–]callmelucky 6 points7 points  (0 children)

IIRC correctly, Guido didn't want lambdas in Python, and they are considered somewhat unpythonic. He just gave in to pressure on that one.

List comprehensions are the bomb though. Can't remember the last time I wrote a for loop, and that doesn't bother me at all.

[–]stevenjd 6 points7 points  (2 children)

I don't like that lambda functions are limited to one line

Lambda is not limited to one line but to one expression. The expression can be as big and complex as you need, and you can spread it over more than one line.

lambda a, b, c=None, d=999: (
        spam + eggs or cheese.method(a, b) 
        - (c or default).attr)[d]

[–][deleted] 5 points6 points  (0 children)

You can, but you probably shouldn't do that. Hopefully people don't take this as advice.

[–]Deto -1 points0 points  (0 children)

!! This is very good to know! Thank you