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

1

u/siddsp Jan 24 '22

It's entirely possible. I guess that means that the generator expression is faster and better than a map and lambda?

1

u/AtomicShoelace Jan 24 '22

At least in those two above tests the generator expression seems to be about 19% faster than the map with lambda. However, I'm not entirely sure - I was genuinely curious if you had some evidence to the contrary as it's perfectly likely I've overlooked something perhaps.