Skip to content

Counting steps · routine

Any duplicates?

Write has_duplicate(nums) returning True if any number appears more than once.

Comparing every pair is correct — and on 2,000 numbers it takes about two million steps. Remember what you have seen instead: a set answers "have I seen this?" in one step.

Run adds print(has_duplicate([1, 2, 1])) after your code, to try it.

Stuck on the idea rather than the code? The Counting steps lesson walks through it.