Last reviewed
Correct answer: A. A set automatically eliminates duplicate values and is unordered
Explanation
A set gives up two guarantees a list makes, and buys something a list cannot offer. The tutorial defines it as "A set is an unordered collection with no duplicate elements." and the library reference as "A set object is an unordered collection of distinct hashable objects." Storing by hash is what makes that trade pay: asking whether an item is in a list walks it element by element, while the same question asked of a set is a single lookup, however large the set has grown.
So the working rule is concrete. If your loop is asking "have I seen this one already?", or you are collapsing a sequence down to its unique values — "Using set() on a sequence eliminates duplicate elements." — reach for a set. Keep the list when position or repeat counts carry meaning, because "Because sets are unordered, iterating over them or printing them can produce the elements in a different order than you expect."
The wrong answers describe a list instead of a set, or impose a limit no Python collection has.
Sources
“A set is an unordered collection with no duplicate elements.”
“A set object is an unordered collection of distinct hashable objects.”
“Using set() on a sequence eliminates duplicate elements.”
Practise 3 questions on this topic
Take Python Data Structures — Timed Test (3 questions) — scored instantly, explanation for every question, no login.