Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Sets in Python (Summary)


Sample Code (.zip)

744 bytes


Course Slides (.pdf)

464.8 KB

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.

00:12 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.

Thomas on Feb. 6, 2020

Very enlightening, thank you.

rgusaas on March 21, 2020

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.

James Uejio RP Team on April 11, 2020

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.

Ben Nduwuba on July 9, 2020

Thanks James for the easy the follow course.

Ghani on Oct. 22, 2020

Excellent course. Thank you!

James Uejio RP Team on Oct. 30, 2020

Thank you Ben and Ghani!

Thakur on Jan. 27, 2021

Excellent course James. Loved it.

James Uejio RP Team on Jan. 28, 2021

Thank you Thakur!

DoubleA on Feb. 7, 2021

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.