Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lambda Functions
#11
(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 :D
Guido 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
Reply
#12
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+
Reply
#13
Quote:for example a tab on a notebook in tkinter
tkinter seems to be the only place i have ever used lambdas.
Recommended Tutorials:
Reply
#14
GUIs, in general, probably use them more than anything else, if for no other reason than you need simple event handlers for almost everything.
Reply
#15
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)]
Reply
#16
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.
Reply
#17
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-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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple lambda functions in zipped list not executing psolar 0 1,570 Feb-13-2020, 12:53 PM
Last Post: psolar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020