December 2017
Beginner
412 pages
10h 8m
English
A set is an unordered collection of distinct items. Unordered means that items aren’t stored in any particular order. Something is either in the set or it’s not, but there’s no notion of it being the first, second, or last item. Distinct means that any item appears in a set at most once; in other words, there are no duplicates.
Python has a type called set that allows us to store mutable collections of unordered, distinct items. (Remember that a mutable object is one that you can modify.) Here we create a set containing the vowels:
| | >>> vowels = {'a', 'e', 'i', 'o', 'u'} |
| | >>> vowels |
| | {'a', 'u', 'o', 'i', 'e'} |
It looks much like a list, except that sets use braces (that ...
Read now
Unlock full access