What is and what is set
in Python?
test = set([1, 2, 3]);
What is and what is set
in Python?
test = set([1, 2, 3]);
Set
is a collection that represents set.
This collection has the characteristic to be disordered and have the elements unique, that is, there is no repetition of elements in this collection type.
There are also methods that do assembly operations, such as union and intersection that respectively return all elements of two set
and the elements they have in common.
>>> a = {1, 2, 3, 4}
>>> b = {3, 4, 5, 6}
>>> print a.union(b)
set([1, 2, 3, 4, 5, 6])
>>> l1 = [1, 2, 3]
>>> l2 = [2, 4, 3]
>>> print set(l1).intersection(l2)
set([2, 3])
Reference link