Hash set
Applies to: general, python
A hash set stores unique values with average O(1) membership tests, by hashing each value to a bucket. It is the go-to tool for de-duplication and "have I seen this before" checks.
seen = set()
for x in nums:
if x in seen:
return True # duplicate
seen.add(x)