16
What is and what is the set
in Python?
test = set([1, 2, 3]);
16
What is and what is the set
in Python?
test = set([1, 2, 3]);
20
Set
is a Collection representing set.
This collection has the characteristic of being disorderly and having the unique elements, that is, there is no repetition of elements in this type of Collection.
There are also methods that do set 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])
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.