14 - how to use sets in python (Python tutorial for beginners 2019)

The Power of Sets: A Comprehensive Guide to Python's Set Data Structure

One of the most powerful data structures in Python is the set, which can be used to store and manipulate collections of unique elements. In this article, we'll delve into the world of sets, exploring their benefits, operations, and usage.

Setting Up a New Library

-------------------------

To begin with, let's create a new library or union of two libraries using the `set()` function in Python. We can do this by passing a list of books to the `set()` function, like so:

```python

library = set(["Harry Potter", "The Lord of the Rings", "Pride and Prejudice"])

library2 = set(["Harry Potter", "To Kill a Mockingbird", "The Great Gatsby"])

```

If we want to create a union of two libraries, we can simply use the `union()` function:

```python

union_library = library.union(library2)

print(union_library) # Output: {'Harry Potter', 'To Kill a Mockingbird', 'Pride and Prejudice', 'The Lord of the Rings', 'The Great Gatsby'}

```

As we can see, the `union()` function combines all the elements from both libraries into one set. However, if there are any duplicates, they will be removed.

Finding Common Elements: Intersection

-----------------------------------

But what if we want to find the common elements between two sets? This is where the `intersection()` function comes in handy:

```python

intersection_library = library.intersection(library2)

print(intersection_library) # Output: {'Harry Potter'}

```

In this case, only the "Harry Potter" book appears in both libraries. The other books are ignored.

Visualizing Sets with Venn Diagrams

----------------------------------

Sets can also be used to visualize relationships between sets using Venn diagrams. Imagine you have two circles representing two sets of elements. What happens when these circles overlap? This is where sets come into play.

For example, let's say we have a library that contains "Harry Potter" and another book called "The Lord of the Rings". We can use sets to find the common elements between these two libraries:

```python

library = set(["Harry Potter", "Pride and Prejudice"])

book2 = set(["The Lord of the Rings", "To Kill a Mockingbird"])

common_elements = library.intersection(book2)

print(common_elements) # Output: {'Harry Potter'}

```

In this case, only the "Harry Potter" book appears in both libraries. The other books are ignored.

Finding Difference Between Sets

------------------------------

But what if we want to find the elements that are unique to one set? This is where the `difference()` function comes in handy:

```python

library = set(["Harry Potter", "Pride and Prejudice"])

book2 = set(["The Lord of the Rings", "To Kill a Mockingbird"])

unique_elements_library = library.difference(book2)

print(unique_elements_library) # Output: {'Pride and Prejudice'}

unique_elements_book2 = book2.difference(library)

print(unique_elements_book2) # Output: {'To Kill a Mockingbird', 'The Lord of the Rings'}

```

In this case, we get the "Pride and Prejudice" book as unique to library, while getting the "To Kill a Mockingbird" and "The Lord of the Rings" books as unique to book2.

Conclusion

----------

In conclusion, sets are a powerful data structure in Python that can be used to store and manipulate collections of unique elements. With operations like union, intersection, difference, and clear, sets provide a flexible way to work with data. By mastering sets, you'll become more efficient in solving problems related to data manipulation, analysis, and visualization.

"WEBVTTKind: captionsLanguage: enhey what's up guys aaron here from clever programmer and today we're going to be talking about something called sets in Python so let's get started so first of all a set is just like a list or a tuple as I explained in previous videos but a little bit different so we already um ate up all the options earlier right so list use brackets okay tuples use parentheses so what's the only thing left oh yeah braces so you might be thinking okay so what if I put something in braces and that's exactly what a set is in Python okay so a set is basically it's another way to group a bunch of things together in Python if you will have a bunch of things together but what's special about them besides the braces so to code them out besides those is you cannot have duplicates in a set all right you cannot have any duplicates so if I had the number is 1 through 10 in the set and then I tried adding 10 again it would just ignore it and it wouldn't add it to the set but if I tried to add 11 then it would add it to the set um set can grow and can grow and get smaller as well I believe but so it's not like a tuple it's not like an strain like a tuple but you can so you can add things to it but you cannot have any duplicates and it's also unordered that's the thing let's try to remember it took me it took me a little bit it is unordered so you cannot iterate through it in any particular order so you cannot be like Oh set at 0 equals this set at 1 equals this like you did with lists and tuples so that's another difference but the main thing is that it doesn't have any duplicates so one really cool thing you can do with sets is actually have a list that has duplicates in it all of whatever it is that you want and then change it to a list cast it to a list no sorry cast it to a set I talked about casting rulers you can actually cast things to a set you can cast a list to a set and a set to a list and what that will do what i just said is if you have a list with duplicates cast it to a set the set will get rid of all the duplicates automatically and then you can cast it back to a list and all of a sudden you got rid of all the duplicates in your list so that's all that's a very very common thing you do with sets but cells can also do a lot more let's explain what I just I just said though so let's say we have a set s equals let's just have a set of mono fruits let's go open Anna actually Lucy is blueberry and raspberry okay so we just have two different types of berries here so that's a set we can print out a set just like a list or a tuple I'll show you that real quick yes it'll have braces see braces here not not brackets or parenthesis but braces and we have two different two different things here in the set its unordered so you actually yeah it's a it's a random order they they're made in a random order but as you can see here raspberry is the second element but when it's printed it actually prints this first like what what gives and then see here now it's it reversed its order so it just it it spits out a random order I don't know what determines that but the point here is that a set is just like a bag of things like if you had a bag of different things you just chuck them all in there it's just there's no order to it it's not like a nice sequential kind of one thing two things three thing for thing five thing okay so let's just try to add something to this set okay so let's say we have blueberry and we have raspberry let's try to add something unique so this function that you can run on the set or any set is just add so you you are right the set here so set dot add and then you can add anything you want to this so let's add strawberry okay a third kind of berry and run this and as you can see I had a set here that has two two types of berries and then I add a third type of berry and which is different than these two so it added it and as you can see when I print it out it's um all three berries are here okay you can also add other data types it doesn't always have to be strings you can have a bunch of different things in there so we can just add four and then boom four pops up and as you can see in a random order let's again random order run it again random order okay so that's the ad but let's try to add let's try to add not strawberry so we're getting rid of this so now that said only has two things in it again um let's try to add blueberry okay oops if we run this this is actually not going to do anything because it's going to notice that this blueberry is already in the set and it's going to ignore it so let's head run and as you can see nothing was added to it if this was a list then the this element W that we have here would have been added to this to the list as well but this is a set so it didn't get added let's actually I want to show you guys that that little duplicate example that's a pretty cool example so let's say we had a list of just numbers okay one one two two one I can type it out one two three three four four four five okay so as you can see we have a duplicate of three here and to duplicate force here if we printed this out you guys can believe me that it'll look just like this right if I printed out this list so I'm not gonna bother printing that out okay but what if we wanted to get rid of all the duplicates what could we do well I said earlier that we can actually put it in a set we can cast it to a set and then cast it back to a list and then we'll have a list like a rid of all the duplicates so let's just say all casting first of all we go like this and then we pop the list in there so we can say no duplicate set this is just the variable name equals set of L so what what this is going to be is going to be a set of this lists without any duplicates so let's see what that looks like print no duplicate set okay and this just come with you so you don't get confused let's run this right let's get rid of this whole thing oh I'll think of a different example later so let's run run this okay so we have this list here 1 2 3 3 4 4 4 5 and then we casted it to a set and then we print it out that set here and as you can see we have a set because there's braces um but it got rid of all the duplicates okay there's no duplicates in here same deal if I had if I had um ABC and even double quotation marks ABC cuz those are equivalent and then I run this only one of these is going to be chosen a random one I believe let's run this and as you can see ABC is is there but it got rid of the duplicate here because these two strings are equivalent um but then you also want to cast it back to a list so we can just go like this simply like this no duplicates it and then we can say no duplicate list alright that makes sense yeah I should I don't know I I tend to use L for like lists and stuff it's probably not the best idea but it's a bad habit I'm trying to kick if you can avoid developing it in the first place I'm not doing a very good idea right now by being a bad example but maybe actually like name it of something like this okay list of numbers why don't we do to do this now I might as well do it now okay guys list of numbers like that so we have a list of numbers and let's get rid of this crap so that this makes sense we have a list of numbers here and then we create a set from that list of numbers with no duplicates and then we see what that set looks like um actually we don't need to see what this set looks like let's just get rid of these boom like that and then and then we casted the set back to a list so now the this list here actually should be this list without any duplicates so let's see what that looks like and as you can see we have a list here like a rid of all the duplicates here so now what you can finally do is actually just change it so list of numbers you can actually just say is equal to no duplicate list and what this will actually do is actually overwrite this one so list of numbers so what this does is let's say you had a list of all these numbers and you want to give it of the duplicates and just completely delete them like let's say you had a bunch of names and a database and you had you had duplicate or a bunch of people in a database you know duplicate records and you didn't care about the duplicate records you just delete them or you had a bunch of videos in a file on your computer and then put two of them are exactly the same and you don't need you don't need the duplicates you can just delete them okay if you don't need those you can do something like that and um you can do something like that and I'll get rid of all the duplicates that might be something actually very useful for this new course we have coming out called how to automate stuff with Python if we're going through file directories and deleting duplicates and whatnot but yes that's might actually come into play there there's something to note there but yeah so those are sets there are also some pretty cool functions and methods you can run on sets because are you guys familiar with Venn diagrams let's let me pull up all image here so Venn diagrams okay diagram so these things here okay you see this thing here you remember these two circles modeling this in school and it's like oh there's like everything and set a the thing instead be and then there's an overlap this is actually what sets are for okay this is what sets are used for in Python so you can actually have sets of things like this and do logic like this like okay there's all these people and then let me think of a better example actually okay yeah I thought of an example let's go back here let's get rid of all this okay remember sets have braces so we're going to be we're going to be creating a a we're gonna have two different libraries okay so let's have library 1 equals a set of oh no Harry Potter Harry pooper I'm actually five I am I'm not 24 I'm five can't multitask hunger games sure hunger games and Lord of the Rings okay so we have a 1 set here and then we have library 2 and then we're gonna have a different set of books here so we're gonna have Harry Potter okay and we're going to have Romeo Romeo and Juliet alright so we have these two separate libraries that have a bunch of books in them these are just strings we just using strings to like signify books and now we have two separate sets and we want to start doing this Venn diagram kind of logic so there's a bunch of different functions you can run okay on on sets to figure out the overlaps and whatnot so let's let's start with I already went over add right I believe you can you can run yeah yeah I did I did you can add things to it to a set by just going like this and only get added if it's not already in this set but first let's let's try this so we listen we have library one okay and then we could um we first of all you can just add two sets together okay you can add two sets together to put it all together but also it'll get rid of duplicates so you notice here how there's Harry Potter and both of these sets so one of these will actually get ignored and then when we add these together it's actually gonna have everything in here and this one Plus Romeo and Juliet it's just gonna ignore this Harry Potter or you're just gonna ignore this very part what if what did I do so let's just try that so you this the function is called Union Union is just a word that you use in in math when it comes to Venn diagrams like that kind of math I figure what it's called discrete math or something um it's unrelated but you can you can add two sets together and that's what you need that so Union just means you're gonna Union them together and Union okay so library 1 Union library 2 or lie-berry - just like that okay and we just call it the town okay let's just yeah I'm gonna say that there's two libraries in a town so I'm all but okay how about this all books in town that makes sense so if we have a town with two different libraries and we want to get all the books in the town without any duplicates then we can get the entire book list by just doing something like this you could go library one Union Library - or you can do library - dot Union Library one it doesn't really matter because it's the same same operation both ways let's hit run there I didn't print it out prints all books in town now let's hit run and as you can see oh let's go here now now as you can see it created a set combining both libraries but it got rid of the duplicate Harry Potter so that's what Union does and the power of a set there's some other other methods and functions I'm going to go over to so um instead of Union what else do we have I had to have it written down here on the side okay now we are going to if okay let's say we wanted to find the books that were at both libraries okay so we can be like okay um like if you if you just want to find the books that are both libraries so at both libraries I don't actually know why you would want to do this in real life like why do you want to know which books or maybe okay yeah I guess that makes sense if you want to be like okay if this one library burns down yeah it took a dark turn but if one library burnt down what books are you gonna have in other libraries as well okay that they're like backed up then you can so you can actually just run this function instead of Union it's going to be intersection okay so this is intersection this means what is it both in both sets so what you're gonna get here is we're going actually going to get Harry Potter because this is the only thing that is in both sets everything else is gonna be ignored this is going to be ignored and this is going to be ignored but Harry Potter is the intersections like when you have a Venn diagram remember you have some things in one circle and other thing than another circle you would have Hunger Games and Lord of the Rings on one side and then Romeo and Julia on the other side and you'd have a Harry Potter in the middle where they were they um overlap you know what I mean so that that's what's gonna happen let's just just run it and you can see how it uh or the rubber were at both libraries how it looks as you can see we get a set of just Harry Potter because that's the only thing that was common here if I if I also had a Hunger Games down here then this will be Harry Potter and Hunger Games okay you're getting the intersection um another another thing you can do is actually get the difference what difference does is it tells you everything in this set that's not in the other set okay so um if we have library one which has Harry Potter Hunger Games and Lord of the Rings and then we use the difference with Harry Potter from Romeo and Juliet then it's going to ignore the Harry Potter and actually just get the difference we're actually only gonna get a Hunger Games Lord of the Rings or only get Romeo and Juliet we're not gonna get all of it oh just just this part or just this part you're getting the difference like what's different about the sets that's where you're getting the difference okay so let's just call this diff okay diff equals library one difference library two so let's run this and see what pops out so as you can see Lord of the Rings and Hunger Games pop out pops out because we called library one and we want to see the difference with library two because library two has Harry Potter in it then we ignore it because um it has this in common so it just gets this if we reverse this then you would actually get Romeo and Juliet instead of Hunger Games and Lord of the Rings you see how that works so yeah these are pretty much sets there's a bunch of functions that you can use there's much more I'm just going over all the all the main ones in these videos but those are the oh there's actually one more called clear but I'll leave that up to you to go figure out what that does look in the Python documentation for sets and see what the function dot clear does probably you probably already guessed it yeah it clears out the set and make it completely empty but go and try it out yourself maybe code it up but those are sets in Python very useful for getting rid of duplicates remember that that's one of the most common uses of it but also if you're doing things like you're doing like some weird logic things are running some like really weird algorithms like I've done some before of my schooling but they're they're very handy thing to know no that's that's that sets are the braces one and that therefore getting rid of duplicates I probably said that three hundred times right now but yeah getting rid of duplicates that's the main use that I know I'm sets are useful so that's it for this video guys thank you for watching and I will see you guys next time good byehey what's up guys aaron here from clever programmer and today we're going to be talking about something called sets in Python so let's get started so first of all a set is just like a list or a tuple as I explained in previous videos but a little bit different so we already um ate up all the options earlier right so list use brackets okay tuples use parentheses so what's the only thing left oh yeah braces so you might be thinking okay so what if I put something in braces and that's exactly what a set is in Python okay so a set is basically it's another way to group a bunch of things together in Python if you will have a bunch of things together but what's special about them besides the braces so to code them out besides those is you cannot have duplicates in a set all right you cannot have any duplicates so if I had the number is 1 through 10 in the set and then I tried adding 10 again it would just ignore it and it wouldn't add it to the set but if I tried to add 11 then it would add it to the set um set can grow and can grow and get smaller as well I believe but so it's not like a tuple it's not like an strain like a tuple but you can so you can add things to it but you cannot have any duplicates and it's also unordered that's the thing let's try to remember it took me it took me a little bit it is unordered so you cannot iterate through it in any particular order so you cannot be like Oh set at 0 equals this set at 1 equals this like you did with lists and tuples so that's another difference but the main thing is that it doesn't have any duplicates so one really cool thing you can do with sets is actually have a list that has duplicates in it all of whatever it is that you want and then change it to a list cast it to a list no sorry cast it to a set I talked about casting rulers you can actually cast things to a set you can cast a list to a set and a set to a list and what that will do what i just said is if you have a list with duplicates cast it to a set the set will get rid of all the duplicates automatically and then you can cast it back to a list and all of a sudden you got rid of all the duplicates in your list so that's all that's a very very common thing you do with sets but cells can also do a lot more let's explain what I just I just said though so let's say we have a set s equals let's just have a set of mono fruits let's go open Anna actually Lucy is blueberry and raspberry okay so we just have two different types of berries here so that's a set we can print out a set just like a list or a tuple I'll show you that real quick yes it'll have braces see braces here not not brackets or parenthesis but braces and we have two different two different things here in the set its unordered so you actually yeah it's a it's a random order they they're made in a random order but as you can see here raspberry is the second element but when it's printed it actually prints this first like what what gives and then see here now it's it reversed its order so it just it it spits out a random order I don't know what determines that but the point here is that a set is just like a bag of things like if you had a bag of different things you just chuck them all in there it's just there's no order to it it's not like a nice sequential kind of one thing two things three thing for thing five thing okay so let's just try to add something to this set okay so let's say we have blueberry and we have raspberry let's try to add something unique so this function that you can run on the set or any set is just add so you you are right the set here so set dot add and then you can add anything you want to this so let's add strawberry okay a third kind of berry and run this and as you can see I had a set here that has two two types of berries and then I add a third type of berry and which is different than these two so it added it and as you can see when I print it out it's um all three berries are here okay you can also add other data types it doesn't always have to be strings you can have a bunch of different things in there so we can just add four and then boom four pops up and as you can see in a random order let's again random order run it again random order okay so that's the ad but let's try to add let's try to add not strawberry so we're getting rid of this so now that said only has two things in it again um let's try to add blueberry okay oops if we run this this is actually not going to do anything because it's going to notice that this blueberry is already in the set and it's going to ignore it so let's head run and as you can see nothing was added to it if this was a list then the this element W that we have here would have been added to this to the list as well but this is a set so it didn't get added let's actually I want to show you guys that that little duplicate example that's a pretty cool example so let's say we had a list of just numbers okay one one two two one I can type it out one two three three four four four five okay so as you can see we have a duplicate of three here and to duplicate force here if we printed this out you guys can believe me that it'll look just like this right if I printed out this list so I'm not gonna bother printing that out okay but what if we wanted to get rid of all the duplicates what could we do well I said earlier that we can actually put it in a set we can cast it to a set and then cast it back to a list and then we'll have a list like a rid of all the duplicates so let's just say all casting first of all we go like this and then we pop the list in there so we can say no duplicate set this is just the variable name equals set of L so what what this is going to be is going to be a set of this lists without any duplicates so let's see what that looks like print no duplicate set okay and this just come with you so you don't get confused let's run this right let's get rid of this whole thing oh I'll think of a different example later so let's run run this okay so we have this list here 1 2 3 3 4 4 4 5 and then we casted it to a set and then we print it out that set here and as you can see we have a set because there's braces um but it got rid of all the duplicates okay there's no duplicates in here same deal if I had if I had um ABC and even double quotation marks ABC cuz those are equivalent and then I run this only one of these is going to be chosen a random one I believe let's run this and as you can see ABC is is there but it got rid of the duplicate here because these two strings are equivalent um but then you also want to cast it back to a list so we can just go like this simply like this no duplicates it and then we can say no duplicate list alright that makes sense yeah I should I don't know I I tend to use L for like lists and stuff it's probably not the best idea but it's a bad habit I'm trying to kick if you can avoid developing it in the first place I'm not doing a very good idea right now by being a bad example but maybe actually like name it of something like this okay list of numbers why don't we do to do this now I might as well do it now okay guys list of numbers like that so we have a list of numbers and let's get rid of this crap so that this makes sense we have a list of numbers here and then we create a set from that list of numbers with no duplicates and then we see what that set looks like um actually we don't need to see what this set looks like let's just get rid of these boom like that and then and then we casted the set back to a list so now the this list here actually should be this list without any duplicates so let's see what that looks like and as you can see we have a list here like a rid of all the duplicates here so now what you can finally do is actually just change it so list of numbers you can actually just say is equal to no duplicate list and what this will actually do is actually overwrite this one so list of numbers so what this does is let's say you had a list of all these numbers and you want to give it of the duplicates and just completely delete them like let's say you had a bunch of names and a database and you had you had duplicate or a bunch of people in a database you know duplicate records and you didn't care about the duplicate records you just delete them or you had a bunch of videos in a file on your computer and then put two of them are exactly the same and you don't need you don't need the duplicates you can just delete them okay if you don't need those you can do something like that and um you can do something like that and I'll get rid of all the duplicates that might be something actually very useful for this new course we have coming out called how to automate stuff with Python if we're going through file directories and deleting duplicates and whatnot but yes that's might actually come into play there there's something to note there but yeah so those are sets there are also some pretty cool functions and methods you can run on sets because are you guys familiar with Venn diagrams let's let me pull up all image here so Venn diagrams okay diagram so these things here okay you see this thing here you remember these two circles modeling this in school and it's like oh there's like everything and set a the thing instead be and then there's an overlap this is actually what sets are for okay this is what sets are used for in Python so you can actually have sets of things like this and do logic like this like okay there's all these people and then let me think of a better example actually okay yeah I thought of an example let's go back here let's get rid of all this okay remember sets have braces so we're going to be we're going to be creating a a we're gonna have two different libraries okay so let's have library 1 equals a set of oh no Harry Potter Harry pooper I'm actually five I am I'm not 24 I'm five can't multitask hunger games sure hunger games and Lord of the Rings okay so we have a 1 set here and then we have library 2 and then we're gonna have a different set of books here so we're gonna have Harry Potter okay and we're going to have Romeo Romeo and Juliet alright so we have these two separate libraries that have a bunch of books in them these are just strings we just using strings to like signify books and now we have two separate sets and we want to start doing this Venn diagram kind of logic so there's a bunch of different functions you can run okay on on sets to figure out the overlaps and whatnot so let's let's start with I already went over add right I believe you can you can run yeah yeah I did I did you can add things to it to a set by just going like this and only get added if it's not already in this set but first let's let's try this so we listen we have library one okay and then we could um we first of all you can just add two sets together okay you can add two sets together to put it all together but also it'll get rid of duplicates so you notice here how there's Harry Potter and both of these sets so one of these will actually get ignored and then when we add these together it's actually gonna have everything in here and this one Plus Romeo and Juliet it's just gonna ignore this Harry Potter or you're just gonna ignore this very part what if what did I do so let's just try that so you this the function is called Union Union is just a word that you use in in math when it comes to Venn diagrams like that kind of math I figure what it's called discrete math or something um it's unrelated but you can you can add two sets together and that's what you need that so Union just means you're gonna Union them together and Union okay so library 1 Union library 2 or lie-berry - just like that okay and we just call it the town okay let's just yeah I'm gonna say that there's two libraries in a town so I'm all but okay how about this all books in town that makes sense so if we have a town with two different libraries and we want to get all the books in the town without any duplicates then we can get the entire book list by just doing something like this you could go library one Union Library - or you can do library - dot Union Library one it doesn't really matter because it's the same same operation both ways let's hit run there I didn't print it out prints all books in town now let's hit run and as you can see oh let's go here now now as you can see it created a set combining both libraries but it got rid of the duplicate Harry Potter so that's what Union does and the power of a set there's some other other methods and functions I'm going to go over to so um instead of Union what else do we have I had to have it written down here on the side okay now we are going to if okay let's say we wanted to find the books that were at both libraries okay so we can be like okay um like if you if you just want to find the books that are both libraries so at both libraries I don't actually know why you would want to do this in real life like why do you want to know which books or maybe okay yeah I guess that makes sense if you want to be like okay if this one library burns down yeah it took a dark turn but if one library burnt down what books are you gonna have in other libraries as well okay that they're like backed up then you can so you can actually just run this function instead of Union it's going to be intersection okay so this is intersection this means what is it both in both sets so what you're gonna get here is we're going actually going to get Harry Potter because this is the only thing that is in both sets everything else is gonna be ignored this is going to be ignored and this is going to be ignored but Harry Potter is the intersections like when you have a Venn diagram remember you have some things in one circle and other thing than another circle you would have Hunger Games and Lord of the Rings on one side and then Romeo and Julia on the other side and you'd have a Harry Potter in the middle where they were they um overlap you know what I mean so that that's what's gonna happen let's just just run it and you can see how it uh or the rubber were at both libraries how it looks as you can see we get a set of just Harry Potter because that's the only thing that was common here if I if I also had a Hunger Games down here then this will be Harry Potter and Hunger Games okay you're getting the intersection um another another thing you can do is actually get the difference what difference does is it tells you everything in this set that's not in the other set okay so um if we have library one which has Harry Potter Hunger Games and Lord of the Rings and then we use the difference with Harry Potter from Romeo and Juliet then it's going to ignore the Harry Potter and actually just get the difference we're actually only gonna get a Hunger Games Lord of the Rings or only get Romeo and Juliet we're not gonna get all of it oh just just this part or just this part you're getting the difference like what's different about the sets that's where you're getting the difference okay so let's just call this diff okay diff equals library one difference library two so let's run this and see what pops out so as you can see Lord of the Rings and Hunger Games pop out pops out because we called library one and we want to see the difference with library two because library two has Harry Potter in it then we ignore it because um it has this in common so it just gets this if we reverse this then you would actually get Romeo and Juliet instead of Hunger Games and Lord of the Rings you see how that works so yeah these are pretty much sets there's a bunch of functions that you can use there's much more I'm just going over all the all the main ones in these videos but those are the oh there's actually one more called clear but I'll leave that up to you to go figure out what that does look in the Python documentation for sets and see what the function dot clear does probably you probably already guessed it yeah it clears out the set and make it completely empty but go and try it out yourself maybe code it up but those are sets in Python very useful for getting rid of duplicates remember that that's one of the most common uses of it but also if you're doing things like you're doing like some weird logic things are running some like really weird algorithms like I've done some before of my schooling but they're they're very handy thing to know no that's that's that sets are the braces one and that therefore getting rid of duplicates I probably said that three hundred times right now but yeah getting rid of duplicates that's the main use that I know I'm sets are useful so that's it for this video guys thank you for watching and I will see you guys next time good bye\n"