Lambda (Anonymous) Functions
Lambda (Anonymous) Functions is a reusable Python snippet. Create small anonymous functions with `lambda`. Ideal for use with `map()`, `filter()`, `sorted()` and other functional tools. The full implementation: # Basic lambda add = lambda x, y: x + y add(3, 5) # 8 # With sorted() - sort by key students = [("Alice", 85), ("Bob", 92), ("Charlie", 78)] sorted(students, key=lambda s: s[1], reverse=True) # [("Bob", 92), ("Alice", 85), ("Charlie", 78)] # With map() numbers = [1, 2, 3, 4] list(map(lambda x: x * 2, numbers)) # [2, 4, 6, 8] # With filter() list(filter(lambda x: x > 2, numbers)) # [3, 4] It belongs to the Built-in Functions area of the standard library. This snippet uses only the Python standard library with no third-party dependencies, so it runs on any modern Python 3 interpreter. Browse more patterns in the snippet library, or paste the code straight into the playground to experiment with it.