Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lambda Functions
#2
They're great when you want to pass something callable without going to the effort to create and name a function. Are you familiar with defaultdict? Takes this example, which shows how to get a defaultdict to give you a 1 instead of a 0

>>> from collections import defaultdict
>>> defaultdict(int)['does not exist']
0
>>> defaultdict(lambda: 1)['does not exist']
1
Lambdas are also useful in map() calls, though Python's comprehensions make that generally less common.
Reply


Messages In This Thread
Lambda Functions - by ATXpython - Sep-28-2016, 10:29 PM
RE: Lambda Functions - by micseydel - Sep-28-2016, 10:35 PM
RE: Lambda Functions - by ATXpython - Sep-29-2016, 01:44 AM
RE: Lambda Functions - by metulburr - Sep-29-2016, 03:10 AM
RE: Lambda Functions - by nilamo - Sep-29-2016, 03:29 PM
RE: Lambda Functions - by j.crater - Sep-29-2016, 05:58 PM
RE: Lambda Functions - by micseydel - Sep-29-2016, 06:00 PM
RE: Lambda Functions - by j.crater - Sep-29-2016, 06:11 PM
RE: Lambda Functions - by snippsat - Sep-29-2016, 06:42 PM
RE: Lambda Functions - by nilamo - Sep-29-2016, 06:08 PM
RE: Lambda Functions - by nilamo - Sep-29-2016, 06:26 PM
RE: Lambda Functions - by Larz60+ - Sep-29-2016, 06:44 PM
RE: Lambda Functions - by metulburr - Sep-29-2016, 07:03 PM
RE: Lambda Functions - by nilamo - Sep-29-2016, 07:05 PM
RE: Lambda Functions - by snippsat - Sep-29-2016, 08:05 PM
RE: Lambda Functions - by ATXpython - Sep-29-2016, 10:09 PM
RE: Lambda Functions - by Larz60+ - Sep-30-2016, 01:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple lambda functions in zipped list not executing psolar 0 1,673 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