Keep first occurrences
Return distinct hashable items in order of first appearance, leaving the input unchanged.
seen = {3, 1}
value = 2
print(value not in seen)Reason about the state
A set records membership while a separate result preserves order. The expected time is linear, with space proportional to distinct items. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return distinct hashable items in order of first appearance, leaving the input unchanged.
The explanation opens here once every check passes.