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