r/learnpython • • Jan 23 '22

I still don't understand the benefit of lambda functions

Hi all,

I've read about lambda functions (for python and other languages), I can WRITE lambda functions just fine, but it seems to me that most places I use them they're just...functions with different syntax. I mean they take args, they return values sometimes. What am I missing here? If anyone has examples of problems they've solved with lambda functions that would also be very helpful.

Thanks!

324 Upvotes

120 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Mar 27 '22

[deleted]

1

u/siddsp Mar 27 '22

You were talking about accidentally misspelling an attribute name. Type-checking is easily solvable by simply checking if the attribute of that name exists with your IDE.

0

u/[deleted] Mar 27 '22

[deleted]

1

u/siddsp Mar 27 '22

Which is why if you're extremely paranoid, you can use your lambda, check if the attribute exists and its type, comment it out, and then replace it with the equivalent attrgetter.

Although I personally am not that unaware about the code I write.

Or better yet, do a simple run and check.

0

u/[deleted] Mar 27 '22

[deleted]

1

u/siddsp Mar 27 '22

If you don't know your own code, static analysis won't save you in any way, and you have bigger things to worry about.

0

u/[deleted] Mar 28 '22

[deleted]

1

u/siddsp Mar 28 '22

It really won't since you would be looking up the attribute either way.

0

u/[deleted] Mar 28 '22

[deleted]

1

u/siddsp Mar 28 '22

Which is why I said you can simply convert an attribute to a string after having it autocompleted by your IDE, making your point invalid.

→ More replies (0)