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 is a set comprehension in Python?
Answer: {x for x in iterable}
Set comprehensions use curly braces without key-value pairs: `{expression for item in iterable}`.
What does `itertools.chain([1,2], [3,4])` produce?
Answer: An iterator yielding 1,2,3,4
`itertools.chain()` creates a single iterator that yields elements from multiple iterables in sequence.
What is a nested list comprehension?
Answer: A list comprehension with multiple `for` clauses
Nested comprehensions use multiple `for` clauses to iterate over nested structures.
What does `any(iterable)` return?
Answer: True if at least one element is True
`any()` returns True if at least one element in the iterable is truthy.
What does `all(iterable)` return if the iterable is empty?
Answer: True
`all([])` returns True by vacuous truth — there are no False elements in an empty sequence.
What is the result of `list(zip([1,2,3], [4,5]))`?
Answer: [(1,4),(2,5)]
`zip()` stops at the shortest iterable, so only the first two pairs are produced.
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, exam format, passing score, retake fee, retake policy, score release, time limit, score validity, exam information · verified Oct 2026
- home.pearsonvue.com — Test delivery · verified Oct 2026