April 2017
Beginner to intermediate
312 pages
7h 23m
English
A set (https://docs.python.org/3/tutorial/datastructures.html#sets) is an unordered collection of immutable elements without duplicate entries. A set could be created as follows:
>>> my_set = set([1, 2, 3, 4, 5]) >>> my_set {1, 2, 3, 4, 5}
Now, let's add a duplicate list to this set:
>>> my_set.update([1, 2, 3, 4, 5]) >>> my_set {1, 2, 3, 4, 5}
Sets enable avoid duplication of entries and saving the unique entries. A single element can be added to a set as follows:
>>> my_set = set([1, 2, 3, 4, 5]) >>> my_set.add(6) >>> my_set {1, 2, 3, 4, 5, 6}
Sets are used to test memberships of an element among different sets. There are different methods that are related to membership tests. We recommend learning about each method using ...
Read now
Unlock full access