Skip to contentSkip to navigation

Functional Python and Modules

Functional Python — cheat sheet

Write concise, expressive data transformations using functional tools.

Lambdas & Higher-Order Functions

square = lambda x: x ** 2
Inline anonymous function.
list(map(lambda x: x*2, nums))
Transform every element lazily.
list(filter(lambda x: x>0, nums))
Keep elements matching predicate.

Decorators

@my_decorator
def func(): pass
Wrap function execution with decorator.
@functools.wraps(func)
Preserve original function __name__ and __doc__.
All cheat sheets