Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
Sets in Python (Summary)
Remember that immutable objects are objects that cannot be modified after they were created, and hashable objects are any type of object that you can call the
hash() method on. All immutable objects are hashable, but not all hashable objects are immutable. Python sets can only include hashable objects.
00:31 You also learned how to define a set in Python. In Section 2, you learned different ways to operate on a set. You learned how to get the length of a set, check membership, and iterate through a set, which were all the same as how you would check length, membership, and iterate through any other iterable such as lists and tuples. You learned some nice built-in methods to find the union set, which is the set of all elements in all sets; the intersection set, which would be only elements that are in all sets; and the difference set, which are all elements that are in the first set and not in any of the rest.
01:08 You also learn how to check if two sets are disjoint, which means they do not have any elements in common. And you learned how to check if a set is a subset of another set, which means every element of the first set is in the second. And proper subset, which is the same as subset except sets can’t be identical.
01:38 In Section 3, you learned different ways to modify a set. You learned about add, remove, discard, pop, and clear. And you learned different update methods, such as update, intersection update, difference update, and symmetric difference update.
02:19 In Section 4, you learned about frozen sets, which are a special type of set because they are immutable. You learned about augmented assignment with frozen sets, which work differently than normal sets because augmented assignment on frozen sets is the same as the expanded out assignment.
02:36 This means that augmented assignment creates a new frozen set instead of mutating the original frozen set because, also, frozen sets are immutable. You also went through “Why sets?” and went through a speed test comparing sets with lists and tuples. You saw that checking membership in a set is much faster than checking membership in a list and tuple, and is one of the main reasons why we use sets in the real world.
Become a Member to join the conversation.