Sep-28-2016, 10:35 PM
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'] 1Lambdas are also useful in map() calls, though Python's comprehensions make that generally less common.