Iteration Helpers
range, enumerate, zip, map, filter, sorted, reversed, iter and next.
Beginner
This is an overview — pick a sub-topic below.
Sub-topics (6)
range()
A lazy sequence of integers: range(stop), range(start, stop[, step]).
Beginner♥ 0🔖 0💬 0
enumerate()
Loops over items together with their index.
Beginner♥ 0🔖 0💬 0
zip()
Pairs up items from several iterables, stopping at the shortest (use strict=True to require equal lengths).
Beginner♥ 0🔖 0💬 0
map() and filter()
Apply a function to every item, or keep only items that pass a test (both are lazy).
Easy♥ 0🔖 0💬 0
sorted() and reversed()
sorted returns a new sorted list (key= and reverse= customise it); reversed iterates backwards.
Beginner♥ 0🔖 0💬 0
iter() and next()
Get an iterator from an iterable, and pull its next item (with an optional default).
Easy♥ 0🔖 0💬 0
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.