May 2019
Beginner
528 pages
29h 51m
English
A set is an unordered collection of unique values. Sets may contain only immutable objects, like strings, ints, floats and tuples that contain only immutable elements. Though sets are iterable, they are not sequences and do not support indexing and slicing with square brackets, []. Dictionaries also do not support slicing.
The following code creates a set of strings named colors:
In [1]: colors = {'red', 'orange', 'yellow', 'green', 'red', 'blue'}In [2]: colorsOut[2]: {'blue', 'green', 'orange', 'red', 'yellow'}
Notice that the duplicate string 'red' was ignored (without causing an error). An important use of sets is duplicate elimination, which is automatic when creating a set. Also, the resulting ...
Read now
Unlock full access