Search⌘ K
AI Features

Functional Programming Toolkit: Maps, Filters, and More

Understand and apply Python's functional programming built-in functions such as map, filter, enumerate, zip, and sorted. Learn how these tools help write cleaner, more efficient code, especially leveraging Python 3's iterator-based returns for better performance.

While writing functional code will be your responsibility, Python also includes a number of tools for functional programming. These built-in functions cover the basics, and they should help you write better code:

map(function, iterable)

map(function, iterable) applies the function to each item in iterable and returns either a list in Python 2 or an iterable map object in Python 3:

Python 3.8
print(map(lambda x: x + 'bzz!', ['I think', 'I\'m good']))
## map wrapped in a list to print the list
print(list(map(lambda x: x + 'bzz!', ['I think', 'I\'m good'])))

filter(function or None, iterable)

filter(function or None, iterable) filters the items in iterable based on ...