Skip to content
AgileLogics
3 min read

Sets

Prerequisites: Lists

A set is an unordered collection of unique values — duplicates are automatically dropped, and checking whether a value exists is very fast.

unique_ids = {1, 2, 2, 3}
print(unique_ids)          # {1, 2, 3}
print(2 in unique_ids)     # True

Expected output

{1, 2, 3}
True

Use a set when you need to remove duplicates or repeatedly check "is this value already in here?"