Sets are implemented as hash table of (unordered) objects, therefore sets are good for get/set/delete/searching items and bad for . Sets do not support indexing, slicing, or other sequence-like behavior.
In [ ]:
a = {1, 2, 'a', (1, 2)}
a
In [ ]:
print(type(a))
In [ ]:
help(a)
In [ ]:
a.add('a')
print(a)
In [ ]:
a.add('a')
print(a)
Mutable objects can not be hashed :-(
In [ ]:
a = set()
a.add([1,2]) # Sets can not contain lists
In [ ]:
a = set() # Empty set
a.add({1,2,3}) # Sets can not contain sets
In [ ]:
a = {1,2,3}
b = {2,3,4}
a.intersection(b)
In [ ]:
a.union(b)
In [ ]:
a = set(range(1000))
print(a)
In [ ]:
%timeit '0' in a
In [ ]:
a = list(range(1000))
print(a)
In [ ]:
%timeit '0' in a