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)
00:00 This is the summary video for the sets course. Let’s go through what you learned. In Section 1, you were introduced to sets and learned what is a set and immutable versus hashable.
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:25 You also learned superset, which is if the first set contains every element of the second set, and proper superset, which is the same as superset, but sets cannot 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.
01:52 These are all the same as their corresponding operators—update, intersection, difference, symmetric difference—but they actually mutate the set instead of returning a new set.
02:03 You learned that augmented assignment is not the same as the expanded out assignment for sets. So if you were to do an intersection update, remember that this always modifies a set.
02:14 It never creates a new set and reassigns it.
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.
03:04 Thank you so much for watching, and if you have any questions or comments, please leave them down below.
I guess I would like a real world example of the use of sets in action. I imagine they could be useful in building sets for visualization purposes where one is attempting to illustrate items in common or not. James did a good job on explaining the mechanics of their use, but I am not getting any real world application to come to mind.
In my experience they are used mostly to check membership and to take advantage of unions and joins. They also are useful in interview questions. I can imagine they’d be useful for visualizing venn diagrams too.
Thanks James for the easy the follow course.
Excellent course. Thank you!
Thank you Ben and Ghani!
Excellent course James. Loved it.
Thank you Thakur!
Thank you James for the great course. Before taking this one I dug in the official documentation and I found it hard to grasp certain concepts. Now, however, everything has become so much clearer. One of the real-life applications of sets is NLP (Natural Language Processing).
Become a Member to join the conversation.
Thomas on Feb. 6, 2020
Very enlightening, thank you.