Python collections: sets
numericSet = {1, 13, 34}
Add
Add elements to the list (mutate)
numericSet.add(100)
# {1, 13, 34, 100}
Add multiple (update
accepts iterables)
list.update([100, 200])
list.update({100, 200})
# {1, 13, 34, 100, 200}
Create a new set with new elements
{*numericSet, 100, 200}
# {1, 13, 34, 100, 200}
Check if exists
if 34 in numericSet:
# whatever
Remove
numericSet.remove(34)
# {1, 13}
# Raises KeyError if the value does not exist in the set
numericSet.discard(34)
# {1, 13}
# Does not raise exceptions
popped = list.pop()
# Pops random argument (unordered set)