SyntaxStudy
Sign Up
Python Lazy Built-ins: zip, map, filter
Python Beginner 3 min read

Lazy Built-ins: zip, map, filter

Lazy Built-ins

In Python 3, zip(), map(), and filter() all return lazy iterators, not lists. Wrap in list() to materialize.

Example
nums = [1, 2, 3, 4, 5]
doubled = map(lambda x: x * 2, nums)  # lazy iterator
print(type(doubled))                   # <class "map">
print(list(doubled))                   # [2, 4, 6, 8, 10]
Pro Tip

map/filter return iterators in Python 3; in Python 2 they returned lists.