1 00:00:00,690 --> 00:00:01,650 Welcome back. 2 00:00:01,740 --> 00:00:06,660 The methods we're going to talk about when it comes to sets are right here. 3 00:00:06,660 --> 00:00:10,490 It looks like a lot but they're quite similar so hang in there. 4 00:00:10,530 --> 00:00:19,020 I have two sets for us are my set which is one through five and then your set which is four through 5 00:00:19,020 --> 00:00:20,490 10. 6 00:00:20,490 --> 00:00:24,580 Now let's go one by one and see what these methods do. 7 00:00:24,710 --> 00:00:32,060 And if you've ever seen Venn diagrams in your school for example two circles that are overlapping each 8 00:00:32,060 --> 00:00:32,410 other. 9 00:00:32,510 --> 00:00:35,500 What we're about to do is quite similar to this. 10 00:00:35,780 --> 00:00:43,190 The first one is difference and sets are very useful when having two sets and comparing them to each 11 00:00:43,190 --> 00:00:44,050 other. 12 00:00:44,060 --> 00:00:51,350 So for example in here difference simply says my set dot difference and we give it another set such 13 00:00:51,350 --> 00:00:52,790 as your set. 14 00:00:52,880 --> 00:01:01,190 If I print this right here and I click Run I get one two three. 15 00:01:01,400 --> 00:01:05,030 It's going to find the difference of the first. 16 00:01:05,030 --> 00:01:14,280 My set with your set so any duplicates between the two which is four and five gets ignored and it only 17 00:01:14,280 --> 00:01:15,350 shows the difference. 18 00:01:15,420 --> 00:01:16,920 That is one two three. 19 00:01:16,920 --> 00:01:21,020 What's different between my set and your set when viewed from my set. 20 00:01:21,030 --> 00:01:24,290 Well your set doesn't have one two three. 21 00:01:24,330 --> 00:01:34,150 What about the next one discard again if we do my set DOD discard it says it removes an element from 22 00:01:34,150 --> 00:01:50,720 a set if it is a member so here we can say discard five and if I do print my set and I click Run I get 23 00:01:50,780 --> 00:02:02,190 none but if I print here my set and I click Run I get one two three four because we've just discarded 24 00:02:02,430 --> 00:02:12,220 Five it modifies our set just to keep our working space clean I'm going to comment this out next is 25 00:02:12,280 --> 00:02:19,770 difference update so I'm going to say my set and then once again let's see what difference update does 26 00:02:21,260 --> 00:02:25,670 remove all elements of another set from this set. 27 00:02:25,670 --> 00:02:39,020 So if I do your set here and once again I do print and I click Run I get none because it just modifies 28 00:02:39,140 --> 00:02:39,740 my set. 29 00:02:39,740 --> 00:02:52,200 So remember we just have to have our print my set and now this my set is updated with just one two and 30 00:02:52,200 --> 00:02:57,500 three because we're updating it so that the differences are removed. 31 00:02:57,510 --> 00:03:04,350 So four and five are removed unlike difference where it just told you the difference without changing 32 00:03:05,480 --> 00:03:18,070 again if we go back here and simply do my set and I click Run you see that my set here was not modified 33 00:03:18,430 --> 00:03:26,280 right here but then my set bottom was modified because of difference update right. 34 00:03:26,360 --> 00:03:27,730 A few more to go. 35 00:03:27,800 --> 00:03:36,170 Intersection and this one once again my set and in here once again let's see what it does. 36 00:03:36,290 --> 00:03:39,980 It just has intersection with something else. 37 00:03:39,980 --> 00:03:40,920 Well let's find out. 38 00:03:41,180 --> 00:03:49,920 If I do your set here and I do print and I run this it's going to give me four or five because that's 39 00:03:49,920 --> 00:03:56,310 the intersection the two common things that my set and your set has. 40 00:03:56,410 --> 00:04:00,320 What about is this joint well. 41 00:04:00,330 --> 00:04:08,700 If I do my set and then your sect feel like I'm saying those words over and over. 42 00:04:08,700 --> 00:04:10,150 Hopefully that's not too annoying. 43 00:04:11,430 --> 00:04:16,730 And then here if let's comment this out we run this. 44 00:04:16,860 --> 00:04:22,630 I get false is disjoint simply says hey are those two circles overlapping. 45 00:04:22,680 --> 00:04:29,530 Do they have anything in common if for example my said didn't had four didn't have four and five and 46 00:04:29,530 --> 00:04:36,420 I click Run I get true because it's disjointed means these sets have nothing in common. 47 00:04:38,330 --> 00:04:38,860 Awesome. 48 00:04:38,870 --> 00:04:39,610 Just a few more. 49 00:04:41,310 --> 00:04:52,580 The next ones we're gonna see is is subset and is superset but actually before we do that let's do union. 50 00:04:52,710 --> 00:04:54,580 Let's see what this does. 51 00:04:54,600 --> 00:04:58,190 Union will say my set 52 00:05:00,960 --> 00:05:05,980 and in here we want to add the other set your set. 53 00:05:05,980 --> 00:05:16,980 If we print this and click Run I get one two three four five six seven eight nine 10. 54 00:05:17,190 --> 00:05:18,670 What did that just do. 55 00:05:18,690 --> 00:05:26,310 Well union just united these sets together but removed any duplicates. 56 00:05:26,310 --> 00:05:28,710 That's kind of nice. 57 00:05:28,830 --> 00:05:31,700 And as you can see it created a new set for us. 58 00:05:31,710 --> 00:05:39,500 It returned to a new set by the way there's actually a shorthand that you can do here in python which 59 00:05:39,500 --> 00:05:47,370 is the shift and then the key above your enter which is right here the straight line. 60 00:05:47,420 --> 00:05:51,410 So shift and then the backslash. 61 00:05:51,410 --> 00:05:54,250 But if you press shift you'll get this that all straight line. 62 00:05:54,590 --> 00:05:59,430 If you print this will remove the brackets here. 63 00:05:59,590 --> 00:06:04,920 Let's run again and you see that works as well. 64 00:06:05,000 --> 00:06:08,600 And by the way this also exists for intersection. 65 00:06:08,720 --> 00:06:14,540 Again you don't see it that often but with intersection you can do the same thing where you just do 66 00:06:14,540 --> 00:06:17,210 the end. 67 00:06:17,400 --> 00:06:18,870 And if you do that 68 00:06:21,790 --> 00:06:26,470 it gives you the intersection of my set and your set. 69 00:06:26,490 --> 00:06:29,470 All right I promise you this is going to be short. 70 00:06:29,460 --> 00:06:36,380 So two other ones is subset and is superset as you can imagine. 71 00:06:36,520 --> 00:06:44,880 My set if let's say my set only has four and five and I say hey is my set. 72 00:06:45,000 --> 00:06:47,660 Is that a subset of your set. 73 00:06:47,910 --> 00:06:58,440 And I print this if I click Run it's true my set is a subset that is it's inside of the circle of your 74 00:06:58,500 --> 00:07:01,710 set because four and five is inside of it. 75 00:07:01,740 --> 00:07:10,700 So my set the entirety of my set is inside of this other set which we call a subset. 76 00:07:10,910 --> 00:07:16,880 On the other hand we also have this idea of superset. 77 00:07:16,880 --> 00:07:27,810 So if I do instead of is subset is superset I'll get false because while my set is not a superset it 78 00:07:27,810 --> 00:07:29,760 doesn't encompass your set. 79 00:07:29,760 --> 00:07:31,990 It's the other way around. 80 00:07:32,490 --> 00:07:36,870 Your set is a superset of my set 81 00:07:40,000 --> 00:07:47,980 because your set encompasses everything that my set has which is four and five homeboy. 82 00:07:48,060 --> 00:07:48,930 That was a lot. 83 00:07:48,930 --> 00:07:53,030 And you're asking yourself there is no way I'm going to memorize any of that. 84 00:07:53,490 --> 00:07:54,340 Well good. 85 00:07:54,360 --> 00:07:56,910 I don't memorize any of this either. 86 00:07:57,210 --> 00:08:04,530 As a matter of fact I usually go to the Python documentation or just google around and because I know 87 00:08:04,530 --> 00:08:11,400 sets exist if I ever want to compare let's say two sets I know to just go here and find the tool that 88 00:08:11,460 --> 00:08:12,180 I want. 89 00:08:12,180 --> 00:08:15,540 That's the cue of a programmer that I keep mentioning over and over. 90 00:08:15,540 --> 00:08:16,900 It's not memorization. 91 00:08:17,040 --> 00:08:20,600 It's the ability to know that there's tools that you can use. 92 00:08:20,700 --> 00:08:22,690 And being able to Google for them. 93 00:08:22,800 --> 00:08:28,080 I know it doesn't sound exciting because in movies you see everybody typing super fast encoding everything 94 00:08:28,110 --> 00:08:31,350 but that's just not real life in real life. 95 00:08:31,350 --> 00:08:37,500 You just google around find solutions because by now you know what sets are you know what sets can do 96 00:08:37,800 --> 00:08:42,980 so that you can google for methods that are appropriate to your problem. 97 00:08:43,110 --> 00:08:44,600 I'll see you in the next one by.