Functional Programming in Python
First-class functions, map/filter, comprehensions, functools and immutability.
Intermediate
from functools import reduce, partial
total = reduce(lambda a, b: a + b, [1, 2, 3])
squares = list(map(lambda x: x * x, range(5)))
evens = [x for x in data if x % 2 == 0] # usually clearer than filter
hex_int = partial(int, base=16)
hex_int("ff") # 255
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.