1 00:00:00,620 --> 00:00:03,770 We've just learned four main set operations in Python and 2 00:00:03,770 --> 00:00:06,960 their corresponding shorthand operators. 3 00:00:06,960 --> 00:00:10,780 I know that was a lot all at once and I hope that my examples helped you out. 4 00:00:10,780 --> 00:00:14,240 And remember that I have teacher's notes for you below the video. 5 00:00:16,500 --> 00:00:21,065 I have an exercise so that we can practice more with some of these methods. 6 00:00:21,065 --> 00:00:23,269 I cleaned up my script a little bit so 7 00:00:23,269 --> 00:00:27,030 you can see our original five sets of omelette ingredients. 8 00:00:29,140 --> 00:00:30,322 For this exercise, 9 00:00:30,322 --> 00:00:34,780 I'm going to be opening my script in interactive mode or interpreter mode. 10 00:00:35,810 --> 00:00:40,640 In the terminal we can invoke this mode by running our script and 11 00:00:40,640 --> 00:00:45,300 passing in the -i command before passing in our file name. 12 00:00:47,470 --> 00:00:52,404 And what this does is that it opens our script, it opens our code so 13 00:00:52,404 --> 00:00:56,905 that we can interactively play with it, it's really fun. 14 00:00:56,905 --> 00:01:03,072 And what I mean by interactively play with is that in the interpreter down here, 15 00:01:04,263 --> 00:01:11,050 I actually have access to everything that I've typed out in my file up here. 16 00:01:11,050 --> 00:01:14,528 I'll show you with the dir command. 17 00:01:17,754 --> 00:01:23,690 I can see that I've got bacon, denver, smothered, turkey and vegetarian. 18 00:01:23,690 --> 00:01:29,660 These variables are all loaded into the interpreter when I pass in the -i command. 19 00:01:29,660 --> 00:01:35,981 And what that allows me to do is that when I'm in my interpreter, 20 00:01:35,981 --> 00:01:41,366 I can use the tab key to autocomplete typing out all of my 21 00:01:41,366 --> 00:01:46,660 variable names so that I can type a little bit faster. 22 00:01:49,080 --> 00:01:51,150 And what else can I do? 23 00:01:51,150 --> 00:01:59,190 I can also Invoke Tab completion. 24 00:02:00,670 --> 00:02:05,791 What that means is that when I put a dot at the end of a Python object, 25 00:02:05,791 --> 00:02:10,457 so my smothered variable, and I press the Tab key two times, 26 00:02:10,457 --> 00:02:15,250 I get a list of all of the methods that belong to that object. 27 00:02:15,250 --> 00:02:21,770 So in this example my smothered variable is a set data type. 28 00:02:21,770 --> 00:02:24,711 And when I've tabbed auto-completed here, 29 00:02:24,711 --> 00:02:30,140 I've retrieved a list of all of the methods that belong to the set class. 30 00:02:30,140 --> 00:02:33,030 And we've learned a lot of these methods already. 31 00:02:33,030 --> 00:02:37,665 In fact, I've taught a lot of these already in our previous videos. 32 00:02:37,665 --> 00:02:42,288 So if you ever need a reminder of what methods belong in what class, 33 00:02:42,288 --> 00:02:48,010 try hopping into interpreter mode to interactively play with your code. 34 00:02:48,010 --> 00:02:50,280 It's very, very helpful and it's very fun. 35 00:02:51,630 --> 00:02:55,710 So for this exercise, we'll be playing around in the interpreter with 36 00:02:55,710 --> 00:03:00,140 our five variables already loaded in and we'll walk through this exercise. 37 00:03:01,730 --> 00:03:06,180 So let's pretend that we're helping a guest in our restaurant make an order. 38 00:03:07,390 --> 00:03:10,039 They say, I've looked at your menu, and 39 00:03:10,039 --> 00:03:14,440 I'm having a hard time making a decision to choose something to eat. 40 00:03:15,460 --> 00:03:17,430 Can you help me order? 41 00:03:17,430 --> 00:03:22,090 Can you help me decide please, between the Denver omelet and the bacon omelet? 42 00:03:23,540 --> 00:03:28,170 Let's imagine using a Venn diagram as we think about how to answer that question. 43 00:03:29,960 --> 00:03:34,680 First, we can tell them about the intersection of the two omelets. 44 00:03:34,680 --> 00:03:37,440 What ingredients that both omelets have in common. 45 00:03:37,440 --> 00:03:41,158 The overlapping middle part of the Venn diagram. 46 00:03:41,158 --> 00:03:45,985 Then we can tell them about what ingredients are unique to one of 47 00:03:45,985 --> 00:03:47,086 the omelets. 48 00:03:47,086 --> 00:03:51,350 First, let's say the Denver omelet, that's on the left side. 49 00:03:51,350 --> 00:03:55,756 And finally, we'll tell them about the unique ingredients of the bacon omelet 50 00:03:55,756 --> 00:03:57,540 which will be on the right side. 51 00:03:58,670 --> 00:04:03,358 The hope is that by presenting the information on their menu in a different 52 00:04:03,358 --> 00:04:06,759 way, we can help them make a decision by comparing and 53 00:04:06,759 --> 00:04:11,620 contrasting the similarities of the ingredients between the two omelets. 54 00:04:12,680 --> 00:04:16,897 So we'll work it out in python now in our interpreter. 55 00:04:16,897 --> 00:04:19,785 I'll move this up so that there's more room for us to play around. 56 00:04:21,743 --> 00:04:26,131 So first, what do both omelets have in common? 57 00:04:34,855 --> 00:04:41,234 Second, what is unique to one of the omelets? 58 00:04:44,668 --> 00:04:49,262 And then what is unique to the other omelet? 59 00:04:53,934 --> 00:04:56,869 In a Venn diagram of these two omelettes, 60 00:04:56,869 --> 00:05:01,017 which ingredients are members of the intersection? 61 00:05:01,017 --> 00:05:06,120 Remember, they wanted to get the Denver and the bacon. 62 00:05:06,120 --> 00:05:12,263 So I can say denver.intersection(bacon). 63 00:05:12,263 --> 00:05:16,580 And this is why I like interpreter mode because when I hit Return, 64 00:05:16,580 --> 00:05:18,750 I get instant feedback. 65 00:05:18,750 --> 00:05:22,186 I don't have to open my script and run it in the console again, 66 00:05:22,186 --> 00:05:26,100 I can just start coding and receive feedback right away about my code. 67 00:05:27,300 --> 00:05:32,318 So the ingredients that are in common of the denver omelet and the bacon omelet 68 00:05:35,541 --> 00:05:38,529 Are cheese, onions and egg. 69 00:05:40,122 --> 00:05:43,129 What ingredients are unique to the denver omelette? 70 00:05:43,129 --> 00:05:45,133 For the difference in this example, 71 00:05:45,133 --> 00:05:50,020 we'll say that the denver omelette is the leftmost set on the Venn diagram. 72 00:05:50,020 --> 00:05:53,743 So we'll make the difference method call on the denver set. 73 00:05:56,898 --> 00:05:59,340 Take the difference of bacon. 74 00:05:59,340 --> 00:06:03,790 And we see that the denver omelet has green pepper, ham, and tomato. 75 00:06:05,370 --> 00:06:08,810 Now, what ingredients are unique to the bacon omelet? 76 00:06:08,810 --> 00:06:12,093 This time I'll put bacon on the left side and 77 00:06:12,093 --> 00:06:17,787 I'll use my shorthand notation to take the difference of bacon and denver. 78 00:06:17,787 --> 00:06:23,660 Bacon minus denver gives me avocado, mushroom and bacon. 79 00:06:25,370 --> 00:06:28,694 So to help our customer answer the question, 80 00:06:28,694 --> 00:06:33,480 I can tell them that both of these omelets have in common. 81 00:06:33,480 --> 00:06:36,030 Let's find that again, bacon and denver. 82 00:06:37,790 --> 00:06:40,130 They both have cheese, onion and egg. 83 00:06:40,130 --> 00:06:43,780 The denver omelette has green pepper, ham and tomato. 84 00:06:43,780 --> 00:06:47,250 And the bacon omelette has avocado, mushrooms and bacon. 85 00:06:48,880 --> 00:06:53,820 And our customer says, you know what, I don't like mushrooms. 86 00:06:53,820 --> 00:06:56,510 I would like to order the denver omelette, please. 87 00:06:57,660 --> 00:07:01,520 Cool, we take that order back to the kitchen and everybody's happy!