![]() |
Lambda Functions - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Lambda Functions (/thread-191.html) Pages:
1
2
|
RE: Lambda Functions - snippsat - Sep-29-2016 (Sep-29-2016, 06:11 PM)j.crater Wrote: Removing lambdas is also something they could do, but it really didn't come across my mind :DGuido van Rossum creator of Python wanted a alternative to lambda, but there was a lot of arguments against it. This is his (final) decision on that matter Let's just *keep* lambda RE: Lambda Functions - Larz60+ - Sep-29-2016 Hello, Here's a place where I really like lambda. when setting a command that requires attributes, for example a tab on a notebook in tkinter The normal 'command' doesn't allow for attributes to be passed (at least I don't believe it does). lambda to the rescue - Here's an example nb.add('cal', label='Find Calls', underline=0, createcmd=lambda w=w, name='cal': self.FindCall(nb, name))Larz60+ RE: Lambda Functions - metulburr - Sep-29-2016 Quote:for example a tab on a notebook in tkintertkinter seems to be the only place i have ever used lambdas. RE: Lambda Functions - nilamo - Sep-29-2016 GUIs, in general, probably use them more than anything else, if for no other reason than you need simple event handlers for almost everything. RE: Lambda Functions - snippsat - Sep-29-2016 To think of something that i use lambda quite often in sorting comes to mind. There is an alternative itemgetter,but then have to import it. >>> lst = [('Tom', 'C', 10), ('Kent', 'A', 12), ('Jenny', 'B', 15)] >>> sorted(lst, key=lambda tup: tup[1]) [('Kent', 'A', 12), ('Jenny', 'B', 15), ('Tom', 'C', 10)] RE: Lambda Functions - ATXpython - Sep-29-2016 Thanks for all the great responses - very helpful. It seems like there are a handful of places where a lambda could be useful, I just havent run into them with my programs yet. As a few of you have mentioned, I think I might just ignore that language feature for the time being and revist if necessary. RE: Lambda Functions - Larz60+ - Sep-30-2016 Hello, Just one more comment, you are wise to let it go for now, but when you want something interesting to read up on: https://dzone.com/articles/lambda-basics-the-mouse-vs-the-python and there are many more Sooner or later, you're going to need it. That's when I learned how to use it (as with most things). Larz60+ [url=https://dzone.com/articles/lambda-basics-the-mouse-vs-the-python][/url] |