In this section, we are going to cover sets, which are unique data structures with interesting properties.
Let's begin our journey into sets by looking at how to create sets, how to read data from them, and how to remove data from them.
In this exercise, we will create a set. We can do so by using the set method or the curly bracket notation:
The first way to create a set is to use the set method. In Python, you can use the built-in set function to create a set. The function takes either an iterable (like a list or a tuple) or a sequence (lists, tuples, and strings are all sequences). Use the set method to define the sets named a and b, like this:
>>> a = set([1,2,3]) >>> a {1, 2, 3} >>> b = set((1,2,2,3,4)) >>> b {1, 2, 3, 4}
Note that in set b, all duplicated values in the original tuple were dropped.
Another way is to use the curly bracket notation. Create a set directly, by using the curly bracket notation, like...