A set is a data type for mutable unordered collections of unique elements. One application of a set is to quickly remove duplicates from a list.
numbers = [1, 2, 6, 3, 1, 1, 6]
unique_nums = set(numbers)
print(unique_nums)
# output:{1, 2, 3, 6}
add
numbers = [1, 2, 6, 3, 1, 1, 6]
unique_nums = set(numbers)
unique_nums.add("7")
print(unique_nums)
# output:{1, 2, 3, 6, '7'}
Delete
a = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
b = set(a)
b.add(5)# delete 5
b.pop()# delete a random number
# {2, 3, 4, 5}