Comprehensions and Iterators Flashcards
6 cards from real PCAP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 Comprehensions and Iterators flashcards as text
What does the `zip()` function do?
Answer: Combines multiple iterables element-by-element into tuples
`zip()` pairs elements from multiple iterables into tuples, stopping at the shortest iterable.
What is the `__iter__` method required for?
Answer: Making an object iterable
The `__iter__` method makes an object iterable by returning an iterator object.
What does `__next__` return when the iterator is exhausted?
Answer: Raises StopIteration
When an iterator has no more items, `__next__` raises `StopIteration` to signal completion.
What does `sorted()` return?
Answer: A new sorted list
`sorted()` returns a new sorted list without modifying the original iterable.
Which built-in function returns the sum of all elements in an iterable?
Answer: sum()
`sum(iterable)` returns the total of all numeric elements in the iterable.
What does `reversed()` return?
Answer: A reverse iterator
`reversed()` returns a reverse iterator, not a list — you need to convert it with `list()` for a list.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. Exam facts are checked against the official sources listed below. Not reviewed by a subject-matter expert. Editorial policy
Sources & references
Exam facts on this page (fees, format, dates, passing scores) are checked against these official sources; the date is our last check. Editorial policy
- pythoninstitute.org — Eligibility, fees, retake fee, retake policy, score release, time limit, score validity · verified Nov 2026
- home.pearsonvue.com — Test delivery · verified Nov 2026