WEBVTT 1 00:00:02.280 --> 00:00:05.510 So continuing on with our discussion on sets (inaudible), 2 00:00:05.510 --> 00:00:08.970 we finish off on our last video just talking about the different methods, and 3 00:00:08.970 --> 00:00:13.654 as you can see on line 61 and 62, when you run this, you get the same results. 4 00:00:13.654 --> 00:00:18.410 You get the same results using dot difference or using the minus sign. 5 00:00:18.410 --> 00:00:21.280 So which one you use depends, again, on which one you find more readable. 6 00:00:21.280 --> 00:00:24.840 In our opinion, the difference method does make it clear that you're working on sets, 7 00:00:24.840 --> 00:00:28.770 which you wouldn't necessarily see just looking at line 62 in isolation. 8 00:00:28.770 --> 00:00:32.780 So again, looking at line 61, it's pretty obvious that .difference 9 00:00:32.780 --> 00:00:36.810 is calling a method, so That's giving you a that it's actually a set. 10 00:00:36.810 --> 00:00:40.320 Now, there's also an update difference method and 11 00:00:40.320 --> 00:00:42.740 that performs the subtraction in place. 12 00:00:42.740 --> 00:00:44.550 In other words, it doesn't return a new set, but 13 00:00:44.550 --> 00:00:49.230 what it does it modifies the set upon which it is called on. 14 00:00:49.230 --> 00:00:50.930 As a result it returns none. 15 00:00:50.930 --> 00:00:53.960 And if you think about that, remember the list dot sort method and 16 00:00:53.960 --> 00:00:56.490 the dictionary dot update methods cause they did the similar thing. 17 00:00:56.490 --> 00:00:58.420 So see how that works. 18 00:00:58.420 --> 00:01:01.090 So lets continue our code down here, so I'll make a bit more space, 19 00:01:01.090 --> 00:01:02.860 it's a little higher up on the screen. 20 00:01:03.880 --> 00:01:07.880 So we'll just make a bit of space in our output. 21 00:01:10.361 --> 00:01:18.730 Then we're gonna print(sorted[even]) print(squares). 22 00:01:18.730 --> 00:01:21.110 And we'll do even .difference. 23 00:01:21.110 --> 00:01:23.390 This time we're doing difference and the score update. 24 00:01:23.390 --> 00:01:25.170 And we're gonna select squares. 25 00:01:25.170 --> 00:01:27.920 So, again we're passing squares as a perimeter and even. 26 00:01:27.920 --> 00:01:31.600 So, that updates a curve on the even variable. 27 00:01:31.600 --> 00:01:33.290 Now, on the even set. 28 00:01:33.290 --> 00:01:35.590 So, we're gonna print and sort it even and 29 00:01:36.970 --> 00:01:39.920 you should find that the changes have been made to it, so let's run that. 30 00:01:41.500 --> 00:01:44.360 So I can say that we started out with this long set, and 31 00:01:44.360 --> 00:01:47.210 then we printed out these squares. 32 00:01:47.210 --> 00:01:50.900 I don't know if you can see them now being removed all the contents from 33 00:01:50.900 --> 00:01:54.675 these squares, cuz we've used Is the difference update to remove them from 34 00:01:54.675 --> 00:01:57.595 the even set and we printed a sort of even set. 35 00:01:57.595 --> 00:02:00.245 You can see those numbers clearly aren't there anymore. 36 00:02:00.245 --> 00:02:03.665 So, moving on the next thing we want to talk about is the the symmetric 37 00:02:03.665 --> 00:02:08.330 difference of two sets, so What that is a symmetric difference of two sets is all 38 00:02:08.330 --> 00:02:12.140 the members that are in one set or the other but not both. 39 00:02:12.140 --> 00:02:15.450 So being symmetric also means that it doesn't matter which way 40 00:02:15.450 --> 00:02:17.380 round you calculate the difference. 41 00:02:17.380 --> 00:02:20.850 And once again what I'll, what we'll do is we'll sort the result before printing it 42 00:02:20.850 --> 00:02:23.590 just to make it easy to interpret The result 43 00:02:23.590 --> 00:02:27.520 you don't normally need to do that in your coding for processing reasons. 44 00:02:27.520 --> 00:02:29.110 We're just making it easy on the screen for you. 45 00:02:29.110 --> 00:02:32.230 So, let's just take this bit of code here because we're going to use that and 46 00:02:32.230 --> 00:02:35.950 post that down here and I'll just comment all that code out. 47 00:02:35.950 --> 00:02:39.960 Okay, so we're gonna stand a code there for sets. 48 00:02:39.960 --> 00:02:44.844 So, what we're going to do now is the symmetric difference so we're gonna Print 49 00:02:47.254 --> 00:02:51.318 symmetric in there. 50 00:02:53.730 --> 00:02:55.800 Symmetric even minus squares. 51 00:02:58.930 --> 00:03:01.420 And we'll do print sorter. 52 00:03:01.420 --> 00:03:05.268 Sorter is just for our eyes but we have to do this to get the symmetric difference 53 00:03:05.268 --> 00:03:09.820 Symmetric difference squares. 54 00:03:09.820 --> 00:03:16.810 Thought so. And we can also do a print symmetric 55 00:03:16.810 --> 00:03:22.395 squares minus even. 56 00:03:22.395 --> 00:03:27.444 Print squares.symmetric 57 00:03:27.444 --> 00:03:32.720 underscore difference even. 58 00:03:32.720 --> 00:03:35.380 We could do the same thing there if we want to, we can sort that as well. 59 00:03:37.560 --> 00:03:40.460 Just to make sure that it's going to come out the same way. 60 00:03:40.460 --> 00:03:41.330 Like I say, we run that. 61 00:03:41.330 --> 00:03:44.400 The output for both is absolutely identical. 62 00:03:44.400 --> 00:03:48.290 So it doesn't matter which order we run it on we get the same results. 63 00:03:50.100 --> 00:03:53.820 And I just remove sort of the, if we run that again. 64 00:03:53.820 --> 00:03:56.560 It says symmetric difference can be thought of 65 00:03:56.560 --> 00:03:59.790 as the opposite of intersection which we covered earlier. 66 00:03:59.790 --> 00:04:02.470 The intersection of the two sets was 4, 6, and 16. 67 00:04:02.470 --> 00:04:07.860 So the symmetric difference is the set of everything except those three values. 68 00:04:07.860 --> 00:04:11.000 Now symmetric difference can also be performed using the carrot. 69 00:04:11.000 --> 00:04:13.140 You know, the sort of up arrow symbol, 70 00:04:13.140 --> 00:04:16.280 which is just really another way of doing exactly the same thing. 71 00:04:16.280 --> 00:04:18.880 There's no performance advantage with either method, so 72 00:04:18.880 --> 00:04:21.120 again it's really just a matter of preference. 73 00:04:21.120 --> 00:04:23.950 What we'd suggest generally is using the methods to make it clear that you're 74 00:04:23.950 --> 00:04:27.830 dealing with sets unless your program was only or mainly using sets, 75 00:04:27.830 --> 00:04:32.170 in which case the shorter operators, again we're talking about In a carrot the and, 76 00:04:32.170 --> 00:04:35.580 and the mono sign will be clearing up because of the context. 77 00:04:35.580 --> 00:04:37.100 Now it may seem to be a quirky you know, 78 00:04:37.100 --> 00:04:41.950 so I took the sorted out and when we ran it we got the same results. 79 00:04:41.950 --> 00:04:44.820 So, that's a little bit of a quirk with a symmetric difference. 80 00:04:44.820 --> 00:04:48.270 When we did even Dot symmetric dot difference squares 81 00:04:48.270 --> 00:04:50.590 we have to sort the result to say the number is in order. 82 00:04:50.590 --> 00:04:53.950 When we did these, the symmetric difference between squares and 83 00:04:53.950 --> 00:04:56.640 even result set printed out in order. 84 00:04:56.640 --> 00:04:59.600 So why that happens we're not really sure so 85 00:04:59.600 --> 00:05:02.790 we're not sure if it happens with all Python implementations and 86 00:05:02.790 --> 00:05:05.660 it's certainly not documented behavior so if you did notice it. 87 00:05:05.660 --> 00:05:07.070 But don't rely on this for your program. 88 00:05:07.070 --> 00:05:10.010 So in other words, if you did want that to be sorted. 89 00:05:10.010 --> 00:05:13.300 And for some reason it's sorting without actual use of the sort method. 90 00:05:13.300 --> 00:05:16.420 You may actually want to put that in there anyway because it might be a bug they fix 91 00:05:16.420 --> 00:05:22.060 in the future versions of Python So, the last 92 00:05:22.060 --> 00:05:27.370 set difference method that we mentioned is symmetric and it's called difference in 93 00:05:27.370 --> 00:05:31.750 It performs really just like the line 67 with a difference update, but obviously in 94 00:05:31.750 --> 00:05:35.630 this case it's using the symmetric difference instead of the difference 95 00:05:35.630 --> 00:05:39.180 It updates the set that it's been called upon rather than reset as you saw when we 96 00:05:39.180 --> 00:05:42.470 talked about the difference updates as you saw again on line 67. 97 00:05:42.470 --> 00:05:44.900 Now there's two ways to remove items from the set. 98 00:05:44.900 --> 00:05:47.660 We can use discard and remove. 99 00:05:47.660 --> 00:05:50.950 The only difference between them is that removes would raise an error 100 00:05:50.950 --> 00:05:53.740 if the island to be removed doesn't exist and 101 00:05:53.740 --> 00:05:56.850 whereas discard won't actually raise an error in that scenario. 102 00:05:56.850 --> 00:05:59.060 So let's see some code that showing that. 103 00:05:59.060 --> 00:06:00.720 I'm just going to comment this last bit of code out. 104 00:06:02.830 --> 00:06:06.910 And I'll just remove this sort of there. 105 00:06:06.910 --> 00:06:10.570 We don't really need it anymore so I'll get rid of those. 106 00:06:10.570 --> 00:06:16.270 See what we're starting out with and now we can start removing some. 107 00:06:16.270 --> 00:06:17.445 So I'm going to do squares. 108 00:06:17.445 --> 00:06:20.390 .discard 4. 109 00:06:20.390 --> 00:06:25.080 Squares dot remove, remove 16. 110 00:06:25.080 --> 00:06:27.069 And squares.discard. 111 00:06:28.440 --> 00:06:30.370 8, it should 112 00:06:36.410 --> 00:06:39.680 show no, it should be no error does nothing. 113 00:06:39.680 --> 00:06:44.700 And obviously we're Because obviously 114 00:06:44.700 --> 00:06:47.650 eight isn't in the set as you can see the set defined on line 73 and 115 00:06:47.650 --> 00:06:52.580 we can do print squares to see that the 416 were removed but 116 00:06:55.640 --> 00:07:02.070 then if we do squares Dot remove eight you should get an error. 117 00:07:03.670 --> 00:07:07.150 First thing I need to fix is error up online, 75, that should fix. 118 00:07:07.150 --> 00:07:10.950 So if we run that now you can see we did get the three. 119 00:07:10.950 --> 00:07:16.140 As you can see that we started out we had 16, 120 00:07:16.140 --> 00:07:21.000 9, 4, 6 and 25 and you can see that 16 and 4 are now removed from the last attempt 121 00:07:21.000 --> 00:07:24.610 which was from line 86, and then we tried to use squares remove. 122 00:07:24.610 --> 00:07:27.850 We actually got an error and again that's the difference between the discard on line 123 00:07:27.850 --> 00:07:31.370 89 because the silent didn't return, didn't raise an error. 124 00:07:31.370 --> 00:07:36.320 But the one on line 87 you can see the remove does raise an error. 125 00:07:36.320 --> 00:07:38.870 That's the main difference, remove does raise an error. 126 00:07:38.870 --> 00:07:40.340 whereas discard doesn't. 127 00:07:40.340 --> 00:07:43.420 If you want to use remove, to safely use that, 128 00:07:43.420 --> 00:07:46.360 you should check the items in the set before attempting to remove it. 129 00:07:46.360 --> 00:07:50.950 We would do something like this to make sure. 130 00:07:50.950 --> 00:07:57.120 We put "if 8 in squares" and squares don't remove 8, as you can see there. 131 00:07:57.120 --> 00:08:00.980 If you run that This time we don't get an error and 132 00:08:00.980 --> 00:08:04.920 that's because we're checking first to see where that eights in the set and 133 00:08:04.920 --> 00:08:09.640 it wasn't in this case so therefore the code on line 88 didn't get executed. 134 00:08:09.640 --> 00:08:12.030 So probably the next question you're asking 135 00:08:12.030 --> 00:08:15.500 Now it would be why do you wanna use remove if discard seems much safer. 136 00:08:15.500 --> 00:08:18.660 Well the reason is, sometimes you may want an error 137 00:08:18.660 --> 00:08:22.500 to be raised if an operation is being attempted that shouldn't be. 138 00:08:22.500 --> 00:08:24.210 So when attempting to discard eight, 139 00:08:24.210 --> 00:08:26.500 there's no way indication that anything's wrong. 140 00:08:26.500 --> 00:08:29.680 And it's not possible to take any action if eight 141 00:08:29.680 --> 00:08:32.210 should not be deleted from the zero or could not be deleted from the set. 142 00:08:32.210 --> 00:08:35.110 So we're gonna look at exceptions later in the course so don't worry too much 143 00:08:35.110 --> 00:08:39.640 about this next bit of code it's really just to show that we can trip an error and 144 00:08:39.640 --> 00:08:44.160 take some other action if we tip to remove an item that doesn't exist from a set. 145 00:08:44.160 --> 00:08:46.590 Sometimes removing them for that reason is more useful so 146 00:08:46.590 --> 00:08:50.135 to do that we can come back here And we can put try. 147 00:08:50.135 --> 00:08:53.810 >> [NOISE] >> And 148 00:08:53.810 --> 00:08:58.765 the codes going to be squares dot remove eight, and put accept. 149 00:08:58.765 --> 00:09:04.362 Key error, print, 150 00:09:04.362 --> 00:09:08.770 item eight. 151 00:09:08.770 --> 00:09:12.010 Is not member of sets 152 00:09:13.670 --> 00:09:18.070 now if you fan run that to the awesome eighties of the set. 153 00:09:18.070 --> 00:09:21.550 Okay so this is try try and receptors. 154 00:09:21.550 --> 00:09:25.670 Exceptions that are used in path in which we won't be going through the details now, 155 00:09:25.670 --> 00:09:27.960 but later in the course you'll see more about those. 156 00:09:27.960 --> 00:09:31.070 The point is we're able to trap the error and do some processing, 157 00:09:31.070 --> 00:09:33.330 which in this case consisted only of printing a message but 158 00:09:33.330 --> 00:09:37.100 it could be anything if the removal failed for some reason. 159 00:09:37.100 --> 00:09:41.710 Now the same is true when attempting to access keys in a dictionary 160 00:09:41.710 --> 00:09:44.490 using the square brackets rather than using a get, so 161 00:09:44.490 --> 00:09:47.220 in other words using [NOISE] When we use. 162 00:09:47.220 --> 00:09:50.340 Trying to get access to keys in the dictionary using the square 163 00:09:50.340 --> 00:09:51.810 brackets instead of using get. 164 00:09:53.280 --> 00:09:55.300 Or they get is very useful, 165 00:09:55.300 --> 00:09:57.760 because we might need to take action if the key is not present. 166 00:09:57.760 --> 00:10:01.890 So that's the reason that partham also provides a way to raise an exception 167 00:10:01.890 --> 00:10:03.900 in error if the key is not present so. 168 00:10:03.900 --> 00:10:06.570 Basically the same concept here for a set. 169 00:10:06.570 --> 00:10:11.270 Okay, so we've now seen how to create a set using either a set [INAUDIBLE] and 170 00:10:11.270 --> 00:10:14.860 closing the members in clearly brackets or the set constructors. 171 00:10:14.860 --> 00:10:17.440 You have also seen how to add and remove members. 172 00:10:17.440 --> 00:10:22.110 As well as creating new sets that are the union and intersection of two other sets. 173 00:10:22.110 --> 00:10:25.580 We can subtract sets from each other as well, which you say. 174 00:10:25.580 --> 00:10:29.610 And in the same way that you can create a set from a list by passing the list 175 00:10:29.610 --> 00:10:32.590 to the set constructor, you can actually go the other way. 176 00:10:32.590 --> 00:10:37.210 So in other words you can create a list from a set using the list constructor. 177 00:10:37.210 --> 00:10:40.780 In fact we did something similar by passing the sets to the sorted 178 00:10:40.780 --> 00:10:43.040 function which will turn to list. 179 00:10:43.040 --> 00:10:46.740 So the last two operations with sets are is subset and is superset. 180 00:10:46.740 --> 00:10:51.830 Now those will be used to test if one set is a sub or super Set of the other set. 181 00:10:51.830 --> 00:10:54.980 Now one set is a sub set of another if all the members 182 00:10:54.980 --> 00:10:56.360 are contained in the other set. 183 00:10:56.360 --> 00:10:58.540 Now similarly, 184 00:10:58.540 --> 00:11:04.080 one set is a super set of another if it contains all the other sets and members. 185 00:11:04.080 --> 00:11:07.920 So if we remove the odd squares from our project, which we're about to do now. 186 00:11:07.920 --> 00:11:09.610 We can see these two methods in action. 187 00:11:09.610 --> 00:11:14.930 So what I'm going to do is just comment this out Encrypt this code. 188 00:11:14.930 --> 00:11:20.425 But we'll just code that as, well so we can stop down at the bottom. 189 00:11:24.380 --> 00:11:28.000 Now what we're going to do for these square. 190 00:11:28.000 --> 00:11:30.040 We'll just make that 4, 6, and 16. 191 00:11:30.040 --> 00:11:31.540 We'll leave the other ones out. 192 00:11:34.120 --> 00:11:40.350 And we can do something like if squares dot is subset even. 193 00:11:40.350 --> 00:11:45.480 We're gonna 194 00:11:45.480 --> 00:11:50.830 do print squares is a subset Copy and we 195 00:11:53.010 --> 00:11:59.462 can also do even dot superset is superset squares. 196 00:11:59.462 --> 00:12:06.150 Print is a super set of squares. 197 00:12:08.850 --> 00:12:09.410 So you can run that. 198 00:12:10.810 --> 00:12:12.760 Squares is a subset of even. 199 00:12:12.760 --> 00:12:14.770 Even is a superset of squares. 200 00:12:14.770 --> 00:12:16.490 So again, a subset. 201 00:12:16.490 --> 00:12:20.730 One set is a subset of another if all its members are contained in the other set. 202 00:12:20.730 --> 00:12:25.480 And for superset, one set is a superset of another If it contains all the other 203 00:12:25.480 --> 00:12:28.030 set's members then you can just say that we've used the example 204 00:12:28.030 --> 00:12:32.790 of inverting the results to be able to show that squares is a subset of even and 205 00:12:32.790 --> 00:12:34.640 even is a superset of squares. 206 00:12:36.080 --> 00:12:38.340 So sets are really not used as often as lists. 207 00:12:38.340 --> 00:12:39.410 Dictionaries, but 208 00:12:39.410 --> 00:12:44.000 they can still be used, can be useful as hopefully you've seen in this code. 209 00:12:44.000 --> 00:12:46.020 So our challenge we're about to do is gonna show you how they 210 00:12:46.020 --> 00:12:47.500 can provide a quick way to modify data. 211 00:12:47.500 --> 00:12:49.720 Now before we start the challenge though, 212 00:12:49.720 --> 00:12:53.870 there's one more type of set available to us in Python It's called a frozen set. 213 00:12:53.870 --> 00:12:58.180 And a frozen set is a immutable set which of course can't be changed. 214 00:12:58.180 --> 00:13:03.100 So, when being unmutable at least we can use a frozen set as a dictionary key, 215 00:13:03.100 --> 00:13:04.100 which is good. 216 00:13:04.100 --> 00:13:07.480 And we can also add a frozen set as a member of a set. 217 00:13:07.480 --> 00:13:10.860 Now keep in mind there's no add methods, there's no add, remove, or 218 00:13:10.860 --> 00:13:13.160 discard methods available with a frozen set. 219 00:13:13.160 --> 00:13:14.680 Once created, it can't be changed. 220 00:13:14.680 --> 00:13:17.350 And obviously that's the reason they haven't added those methods. 221 00:13:17.350 --> 00:13:24.920 So to use those, It'll 222 00:13:24.920 --> 00:13:31.250 give you something like even equals frozen set range 0 100 2. 223 00:13:31.250 --> 00:13:35.650 And print even 224 00:13:37.750 --> 00:13:43.460 even dot add three notice that the doesn't come up and if we run 225 00:13:43.460 --> 00:13:48.400 that we're getting an error because frozen set object has no attribute for add. 226 00:13:48.400 --> 00:13:51.020 And as I mentioned, it hasn't got those methods because it's immutable. 227 00:13:51.020 --> 00:13:54.050 Once we create it, we can't modify it. 228 00:13:54.050 --> 00:13:56.650 Now other than an inability to add or remove members, 229 00:13:56.650 --> 00:14:00.810 frozen sets behave just like regular sets and can be used to create unions, 230 00:14:00.810 --> 00:14:03.720 intersections, and can be subtracted from other sets. 231 00:14:03.720 --> 00:14:08.460 Now you can't call difference_update or symmetric_difference_update 232 00:14:08.460 --> 00:14:11.940 on a frozen set, of course, because A frozen set isn't mutable. 233 00:14:11.940 --> 00:14:15.680 What you can do is you can pass a parameter to a different underscore update 234 00:14:15.680 --> 00:14:17.300 core on a regular set. 235 00:14:17.300 --> 00:14:18.710 Now before we move onto the challenge, 236 00:14:18.710 --> 00:14:21.690 we looked at many operators that do the same job as the methods. 237 00:14:21.690 --> 00:14:25.295 And there's a nice table in the path documentation for 238 00:14:25.295 --> 00:14:28.770 2.7 showing the methods and the equivalent operators 239 00:14:28.770 --> 00:14:32.680 Not only use the table that was much of the text no longer applies to Python 3. 240 00:14:32.680 --> 00:14:36.860 So that's important so ignore the text and just see the refer to the table. 241 00:14:36.860 --> 00:14:42.480 So I'm just gonna bring that up on the screen so you can see There and 242 00:14:42.480 --> 00:14:45.490 we're gonna put this link in the resources section. 243 00:14:45.490 --> 00:14:48.770 So refer to that as well, but you can see that's giving you a good overview of what 244 00:14:48.770 --> 00:14:52.260 the various operations are for sense. 245 00:14:52.260 --> 00:14:55.155 And just out of interest, the same information is available in the Tree 246 00:14:55.155 --> 00:14:58.765 documentation but it's not laid out in a helpful table than it is there and 247 00:14:58.765 --> 00:15:01.925 I think it is really quite helpful being able to see that all getting there. 248 00:15:01.925 --> 00:15:04.825 So probably I could link for you to bookmark. 249 00:15:04.825 --> 00:15:06.185 All right, it's time for a challenge. 250 00:15:06.185 --> 00:15:10.685 Let's go back to our code and we're gonna create a new file. 251 00:15:10.685 --> 00:15:17.390 [NOISE] >> We're gonna copy and paste challenging. 252 00:15:18.830 --> 00:15:19.720 So, here's the challenge. 253 00:15:19.720 --> 00:15:21.790 Create a program that takes some text and 254 00:15:21.790 --> 00:15:26.030 returns a list of all the characters in the text that are not vowels. 255 00:15:26.030 --> 00:15:27.440 Sorted in alphabetical order. 256 00:15:27.440 --> 00:15:30.590 And you can either answer the text from the keyboard or 257 00:15:30.590 --> 00:15:33.020 initialize a string variable with a the string. 258 00:15:33.020 --> 00:15:34.450 Now obviously we wanted to use sets. 259 00:15:34.450 --> 00:15:37.130 So this is where the whole idea of this is we're using sets. 260 00:15:37.130 --> 00:15:39.760 So you should be using a set with this challenge. 261 00:15:39.760 --> 00:15:42.480 Okay so, go away and see if you can figure out that challenge. 262 00:15:42.480 --> 00:15:45.200 And when you're ready to see the solution, come back and we're make a start on it. 263 00:15:49.155 --> 00:15:50.615 Let's have a look at that. 264 00:15:50.615 --> 00:15:52.805 Let's type some text in. 265 00:15:52.805 --> 00:15:58.195 Sampletext equals "python is a very powerful language". 266 00:15:58.195 --> 00:16:02.785 So, how would we do that? 267 00:16:02.785 --> 00:16:10.050 We would type "vowels equals Frozenset, aeiou. 268 00:16:10.050 --> 00:16:16.143 Alternatively, you could have done something like this 269 00:16:16.143 --> 00:16:22.607 vowels = ("a", 270 00:16:22.607 --> 00:16:26.591 "e", "i", "o", "u"). 271 00:16:28.100 --> 00:16:31.640 But thank you, that takes more topics so the one that for 272 00:16:31.640 --> 00:16:33.490 instance we dont that it was way quicker. 273 00:16:34.620 --> 00:16:38.060 So, then we do funnel set, equals set. 274 00:16:38.060 --> 00:16:42.953 Sample text, dot difference 275 00:16:45.300 --> 00:16:48.790 Print final set [NOISE] >> And 276 00:16:48.790 --> 00:16:54.754 then we can finally do something like final lists equals sorted. 277 00:16:54.754 --> 00:16:59.640 FInal set and print. 278 00:16:59.640 --> 00:17:01.225 [NOISE] On a list. 279 00:17:03.025 --> 00:17:03.595 So if you run that. 280 00:17:05.105 --> 00:17:06.935 And I think I need to [INAUDIBLE] some [INAUDIBLE]. 281 00:17:06.935 --> 00:17:08.075 So I need to go back to my other file. 282 00:17:08.075 --> 00:17:10.075 I'm actually running the wrong program file. 283 00:17:10.075 --> 00:17:12.275 Unless you just run this one here as well first. 284 00:17:14.385 --> 00:17:15.805 Run challenge. 285 00:17:15.805 --> 00:17:16.965 Just to confirm that it works. 286 00:17:16.965 --> 00:17:20.525 So you can see that the first line shows the answer to the sorted version 287 00:17:20.525 --> 00:17:21.555 of the sort. 288 00:17:21.555 --> 00:17:22.675 And the second line as you can see. 289 00:17:22.675 --> 00:17:24.230 That's in alphabetical order. 290 00:17:24.230 --> 00:17:26.140 Noting the upper case and lower case and 291 00:17:26.140 --> 00:17:29.370 spaces have got a different ordering than the lower case equivalence. 292 00:17:29.370 --> 00:17:33.240 So because sets don't contain duplicates, we get the list that we wanted with each 293 00:17:33.240 --> 00:17:35.850 character only occurring once on the list as you can see there. 294 00:17:35.850 --> 00:17:37.650 And we've used a frozen set for 295 00:17:37.650 --> 00:17:40.310 the vals because the members shouldn't change in English. 296 00:17:40.310 --> 00:17:43.760 If you wanted to test say for the worst language and we add w and y to the set. 297 00:17:43.760 --> 00:17:46.320 Then the frozen wouldn't be appropriate in this scenario. 298 00:17:46.320 --> 00:17:50.020 Just to go back to that other area, that was coming up because 299 00:17:50.020 --> 00:17:52.880 I hadn't come into that line out which was invalid because we're using a frozen set. 300 00:17:53.990 --> 00:17:55.710 So that's actually the challenge. 301 00:17:55.710 --> 00:17:57.540 That's any few lines of code and 302 00:17:57.540 --> 00:18:01.810 again I just want to reinforce how powerful Python is to be able to do things 303 00:18:01.810 --> 00:18:04.390 that are relatively complex in such a few lines of code. 304 00:18:04.390 --> 00:18:07.060 It's really a fantastic language for that. 305 00:18:07.060 --> 00:18:11.010 Ok, so that's the end of this video and the end of this section, actually. 306 00:18:11.010 --> 00:18:14.280 So I've worked on quite a few things in this section trying 307 00:18:14.280 --> 00:18:16.670 to get dictionaries and sets out of the way. 308 00:18:16.670 --> 00:18:17.600 And we're now done with that. 309 00:18:17.600 --> 00:18:21.220 In the next section we're going to start working on input and output in Python, so 310 00:18:21.220 --> 00:18:22.730 see you in the next section.