1 00:00:00,330 --> 00:00:04,440 Python sits, so that is another data available in PyCon. 2 00:00:05,590 --> 00:00:12,960 In Python is it is an unordered collection of unique items, no duplicate elements are allowed in, 3 00:00:12,970 --> 00:00:17,910 set and must be immutable that bones which cannot be changed. 4 00:00:18,370 --> 00:00:24,350 So however, the set itself is mutable, we can add or remove items from it. 5 00:00:24,790 --> 00:00:27,450 So now we have defined what is a set. 6 00:00:27,640 --> 00:00:32,800 And in Python we usually include the set within Kali Brezhnev's as set. 7 00:00:32,800 --> 00:00:39,520 Members must be unordered and they'll be each and every little item will be unique in values. 8 00:00:40,000 --> 00:00:46,980 So this can be used to perform the mathematical set operations like your union intersection, semantic 9 00:00:47,170 --> 00:00:48,820 difference and so on. 10 00:00:51,210 --> 00:00:58,800 So here we are discussing what is said union, so let us suppose a Z visa visit and if you do the union, 11 00:00:58,950 --> 00:01:03,780 that is a union B, so these are the elements were selecting deputies were selecting all the elements 12 00:01:04,050 --> 00:01:06,640 either belonging to A or B or both. 13 00:01:07,110 --> 00:01:09,020 We are going for to set intersection. 14 00:01:09,390 --> 00:01:14,820 So if you take the intersection between the set and B, then all those elements will be belonging which 15 00:01:14,820 --> 00:01:17,190 are common between A and B sets. 16 00:01:18,600 --> 00:01:21,660 Here you is actually standing for the universal set. 17 00:01:23,360 --> 00:01:25,760 Next one is a set of operations continue. 18 00:01:25,790 --> 00:01:32,270 That is the difference if you do A minus B, if you do A minus B, then you are remaining with those 19 00:01:32,270 --> 00:01:39,410 elements, which will be in A, not in B, but if you do the set set symmetric difference. 20 00:01:39,650 --> 00:01:46,970 In that case, if you go for a set symmetric difference B, then those elements will be will be selected, 21 00:01:47,120 --> 00:01:51,140 which could be either in A or in B, not in common. 22 00:01:53,290 --> 00:02:02,260 So here we are having the Biton set methods, so Ed, so he can add an element to our set clear, remove 23 00:02:02,260 --> 00:02:08,710 all elements from a set copy returns the A copy of a set next. 24 00:02:08,720 --> 00:02:09,670 What is the difference? 25 00:02:09,820 --> 00:02:14,160 Return the difference of two or more sets as a new set. 26 00:02:14,410 --> 00:02:16,330 They're going for the difference a bit. 27 00:02:16,750 --> 00:02:19,600 Discard remove an element from the set. 28 00:02:19,720 --> 00:02:22,030 If it is a member, do nothing. 29 00:02:22,210 --> 00:02:30,190 The element is not belonging to the set, not a member of the set intersection intersection a bit is 30 00:02:30,190 --> 00:02:40,000 disjoined return true if two sets have a null intersection is subsect return true if another set contains 31 00:02:40,030 --> 00:02:41,290 this particular set. 32 00:02:43,090 --> 00:02:45,350 We're having this is superset. 33 00:02:45,580 --> 00:02:53,050 We are having this pop that is the Bob method that is remove and return an arbitrary set element, it 34 00:02:53,050 --> 00:02:55,400 is clear if the set is empty. 35 00:02:55,510 --> 00:03:01,060 So in this scene, you see all the methods we have discussed with the respective shot discussions. 36 00:03:02,430 --> 00:03:07,580 OK, next one is all return to if all elements of the set are true. 37 00:03:07,740 --> 00:03:13,660 So these are the list of methods which are python building functions, which which are applicable with 38 00:03:13,660 --> 00:03:14,270 set also. 39 00:03:14,580 --> 00:03:22,440 So any return true if any element of the set is true, enumerate, return and enumerate object, it 40 00:03:22,440 --> 00:03:28,440 contains the index and the value of all the items of the set as a appear so index. 41 00:03:28,440 --> 00:03:32,810 That is a position number and the value so that can fall appear and that will be printed. 42 00:03:33,000 --> 00:03:34,090 That would be the output here. 43 00:03:34,320 --> 00:03:36,030 So now we are going for this line. 44 00:03:36,210 --> 00:03:37,520 That is the return, the length. 45 00:03:37,540 --> 00:03:39,470 That is a number of elements in the set. 46 00:03:39,630 --> 00:03:41,420 So these are the other methods are there? 47 00:03:41,640 --> 00:03:45,990 These are the python building functions which can be applied on the set. 48 00:03:46,890 --> 00:03:52,410 So I think for the better clarity, let us go for one practical demonstration to show you that how these 49 00:03:52,410 --> 00:03:54,710 methods can be applied on the set. 50 00:03:54,720 --> 00:03:59,430 And before that, obviously, we should we should show you that what the what is a set, how to define 51 00:03:59,430 --> 00:04:03,990 it and what are the different basic operations which you can carry out on? 52 00:04:03,990 --> 00:04:04,340 Is it. 53 00:04:04,500 --> 00:04:11,940 So here is the demonstration for you is it is an unordered collection of items that means within the 54 00:04:11,940 --> 00:04:16,320 items, within the members of the set that is not ordering the elements. 55 00:04:16,470 --> 00:04:21,630 The items can be in any order and every element must be unique, not duplicate. 56 00:04:21,810 --> 00:04:25,020 Elements will be allowed in a set and must be imitable. 57 00:04:25,020 --> 00:04:28,370 That means those elements cannot be updated, cannot be changed. 58 00:04:28,830 --> 00:04:31,180 However, the set itself is mutable. 59 00:04:31,200 --> 00:04:39,150 That means we can add or remove items from asset sales can be used for to perform the mathematical set 60 00:04:39,200 --> 00:04:44,070 operations like our union intersection, semantic differenced, etc.. 61 00:04:44,520 --> 00:04:51,480 So let us discuss how to create one set here to define one set of integers in case upset. 62 00:04:51,480 --> 00:04:56,640 The elements will be separated by commas and the whole set will be enclosed within calibrations. 63 00:04:56,970 --> 00:05:02,780 So if I predict you can find that the set has been formed, a sip may have different type of data. 64 00:05:02,790 --> 00:05:05,960 That means elements will be from mixed data types. 65 00:05:06,210 --> 00:05:12,000 So here we are having this hundred and one of the type of integer organismal is the type of string. 66 00:05:12,210 --> 00:05:16,770 And here we are having one tuple that can be also asset element. 67 00:05:16,950 --> 00:05:20,730 So he can find that respective mindset, too, has got printed. 68 00:05:21,270 --> 00:05:26,190 If we while defining one set, if I put some duplicate values, then those duplicate values will be 69 00:05:26,190 --> 00:05:26,850 eliminated. 70 00:05:26,850 --> 00:05:30,420 Only that unique values will be there in the set ultimately. 71 00:05:31,330 --> 00:05:37,240 Now, in this case is it cannot have multiple items here, you can find that we are defining one set 72 00:05:37,420 --> 00:05:42,550 or at least is as one of the elements, but list is containing multiple items. 73 00:05:42,580 --> 00:05:45,160 So this particular set cannot be formed. 74 00:05:45,160 --> 00:05:46,960 So if I are going printing. 75 00:05:48,140 --> 00:05:55,820 If I try to form a different one, set it, then type it is coming, an honorable type list is their 76 00:05:55,820 --> 00:05:57,110 respective error message. 77 00:05:57,440 --> 00:06:03,800 So you can find that creation of a set from the list as one of the elements is not possible. 78 00:06:04,370 --> 00:06:05,990 So we can make a set. 79 00:06:07,010 --> 00:06:10,620 But we can make a set from a list using the method set. 80 00:06:10,910 --> 00:06:12,360 So here we are having one list. 81 00:06:12,770 --> 00:06:18,510 You are doing one method set here, and then we're going to get one set accordingly. 82 00:06:18,950 --> 00:06:26,670 And now if I want to make one list from this set, the set will be enclosed within the calibrations. 83 00:06:26,690 --> 00:06:32,690 And here we are using the method list and then we can get a list from this set here so we can find that 84 00:06:32,690 --> 00:06:34,670 we have got one list here and here. 85 00:06:34,670 --> 00:06:37,070 You can find the type of the my one. 86 00:06:37,100 --> 00:06:39,030 So it had the class type list here. 87 00:06:40,460 --> 00:06:45,850 Next, we're going for operations on a set so honest that we can perform multiple different operations. 88 00:06:45,860 --> 00:06:47,530 So let me go one by one. 89 00:06:49,080 --> 00:06:54,750 So at first, we are defining this particular set here, having the value 11, 30 to 44, 66 and 55, 90 00:06:54,990 --> 00:06:58,260 you can see this set of values that there might be in the different order. 91 00:06:58,830 --> 00:07:03,070 So now the set members cannot be accessed using index. 92 00:07:03,070 --> 00:07:04,210 So zero is the index. 93 00:07:04,230 --> 00:07:07,710 So if I want to access the mind, set one zero. 94 00:07:07,710 --> 00:07:10,110 If I want to access this one, it will be coming. 95 00:07:10,380 --> 00:07:16,740 And that type of the name of the edit is type error and set object does not support indexing is the 96 00:07:16,740 --> 00:07:17,580 error message. 97 00:07:18,480 --> 00:07:20,180 So that means I cannot do this one. 98 00:07:20,730 --> 00:07:25,080 That means indexing is not allowed, not getting supported on a set. 99 00:07:26,350 --> 00:07:33,940 OK, no next one is that so if we go for adding one single item so we can use that method and so in 100 00:07:33,940 --> 00:07:37,440 that case, 77 will be added as one of the elements. 101 00:07:37,810 --> 00:07:42,540 But if I want to add multiple items, then you can go for the method update. 102 00:07:42,550 --> 00:07:48,580 And here the multiple items are to be enclosed within square because that means it is a list. 103 00:07:48,880 --> 00:07:54,670 So list of items can be can be passed as input into the method that is our object. 104 00:07:54,860 --> 00:07:55,570 In the case. 105 00:07:55,630 --> 00:08:01,280 You can find that at 19 and 22, the three values have got added to the set. 106 00:08:01,870 --> 00:08:04,270 Now you see, we can go for the update. 107 00:08:04,510 --> 00:08:08,990 In the case of update, we can add at least we can add a set. 108 00:08:09,340 --> 00:08:11,740 So here is the 100, 300, 400. 109 00:08:12,070 --> 00:08:16,360 They are nothing but a set of 100 and 100 to nothing but a list. 110 00:08:16,600 --> 00:08:22,390 So looking at the brackets and closed, we can easily find and then you can find that this particular 111 00:08:22,390 --> 00:08:26,080 mindset one is having those values included and added. 112 00:08:28,630 --> 00:08:34,870 Now we are going for remove and discard so you can find that in of remove and discard so initialised 113 00:08:34,870 --> 00:08:40,000 mindset, so ETWAS mindset, one has got this set of values and we have printed that one. 114 00:08:40,540 --> 00:08:45,070 Now we are going for discard for that discard an element which is not present. 115 00:08:45,250 --> 00:08:51,640 But you can find that no edit is coming, no error messages coming because the discard will handle that 116 00:08:51,640 --> 00:08:53,250 error in any situation. 117 00:08:53,560 --> 00:08:55,480 So my let's set one. 118 00:08:55,720 --> 00:08:59,650 If we go for my second printing then I'm getting the same set of items. 119 00:08:59,890 --> 00:09:05,730 But if you use them instead of using the method discard, if you use that method remove and if you pass 120 00:09:05,800 --> 00:09:11,140 of an element which is not there in the set, you'll be getting one error. 121 00:09:11,140 --> 00:09:12,940 So I'm just going to show you that one. 122 00:09:15,100 --> 00:09:21,280 So this is known as the name of it, so there is a name, my set is not defined here, so let me go 123 00:09:21,280 --> 00:09:22,720 for this, my one, I think. 124 00:09:23,670 --> 00:09:30,690 OK, so now if I go for this, I can find this one that is accurate so that B6 is not present in the 125 00:09:30,690 --> 00:09:36,330 respective set because you can find that six is not present there, but 66 is present. 126 00:09:36,330 --> 00:09:38,740 So 66 can be deleted, can be removed. 127 00:09:39,030 --> 00:09:40,520 So in case something goes up. 128 00:09:40,530 --> 00:09:46,560 So one very big difference between this discard and this remove is that in case of discard, if the 129 00:09:46,560 --> 00:09:51,810 element, whatever we are passing as input argument is not present, it is not producing any error, 130 00:09:52,140 --> 00:09:55,770 but in case of remove, it is producing an error on the name of the error. 131 00:09:55,770 --> 00:09:56,520 Izquierda. 132 00:10:00,720 --> 00:10:06,510 Now, if you go for to discard 44, if you want to print this myself, one in that case, I can find 133 00:10:06,510 --> 00:10:08,540 that this 44 has been deleted. 134 00:10:08,550 --> 00:10:15,900 If you go for this remove 55 and 55 is existing, the respective will get deleted from the set. 135 00:10:18,620 --> 00:10:24,140 So now here we are going for the method that is a pop, and here we are having one set defined. 136 00:10:25,120 --> 00:10:31,180 And now we are going for this mindset, one dark pop method, and then we can find that 33 has been 137 00:10:31,180 --> 00:10:33,750 popped, popped out, has been deleted. 138 00:10:33,760 --> 00:10:38,770 If you go for another time, pop method that 66 has been deleted here, this particular values can be 139 00:10:38,770 --> 00:10:40,020 selected randomly. 140 00:10:40,600 --> 00:10:41,890 So clear mind set. 141 00:10:41,890 --> 00:10:43,720 In that case, the set will be existing. 142 00:10:43,720 --> 00:10:47,790 My statement will be existing, but its all its elements will get cleared. 143 00:10:48,130 --> 00:10:50,800 So I'm going to print my set one. 144 00:10:50,800 --> 00:10:57,010 After issuing this clear method, we can find that at the city's existing, but no elements are there. 145 00:11:01,030 --> 00:11:06,370 Let us go for a different set of operations, because we are going for this union, so we are having 146 00:11:06,370 --> 00:11:09,900 mindset one, we are having mindset to bring those two sets. 147 00:11:10,090 --> 00:11:16,920 Now, this union can be done using the idea, using the operator filter or using this method, not union. 148 00:11:17,380 --> 00:11:20,260 So my set one dark union mindset, too. 149 00:11:20,530 --> 00:11:26,890 So I have shown that in whatever the way in which we are doing the union ultimately leading to the same 150 00:11:26,890 --> 00:11:30,070 result, that means union is taking place in union. 151 00:11:30,070 --> 00:11:32,020 The duplicate values will be orcharding once. 152 00:11:32,290 --> 00:11:35,560 So four and five, they are the duplicate values between these two sets. 153 00:11:35,560 --> 00:11:42,100 My set one of say two, but they will be orcharding once because set will all is a collection of unordered 154 00:11:42,190 --> 00:11:43,300 distinct elements. 155 00:11:43,450 --> 00:11:47,320 So they'll be orcharding once, ultimately in the union after union. 156 00:11:47,800 --> 00:11:48,250 What happened? 157 00:11:48,250 --> 00:11:51,520 This intersection next one is our intersection. 158 00:11:51,520 --> 00:11:56,080 You can find that mindset one and myself to at having the set of values there. 159 00:11:56,290 --> 00:12:02,110 And if you go for the intersection then we're landing with this four and five only intersection can 160 00:12:02,110 --> 00:12:08,500 be done using the operator ampersand, all using my set one dot intersection mindset to. 161 00:12:09,730 --> 00:12:14,680 Next one, we are going for the set difference so it gets upset difference that you can use the operator 162 00:12:14,690 --> 00:12:19,000 that is a minus, or you can use a method that is intersection. 163 00:12:19,300 --> 00:12:23,680 So we can see that only the common elements will be coming out from the intersection. 164 00:12:23,830 --> 00:12:26,290 So this is one of the very important operations on set. 165 00:12:26,620 --> 00:12:31,750 So we are finding that four and five are the common elements in between the set mindset one and Mindset 166 00:12:31,750 --> 00:12:32,020 two. 167 00:12:32,140 --> 00:12:33,230 So they are coming up. 168 00:12:33,580 --> 00:12:35,190 We are going for the set difference. 169 00:12:35,470 --> 00:12:38,790 So here we are having this this mindset one on my set, too. 170 00:12:39,160 --> 00:12:41,130 So the restrictive rules are there. 171 00:12:41,320 --> 00:12:48,580 So now when we are going for this difference, then mindset one minus mindset to you will be landing 172 00:12:48,580 --> 00:12:49,420 with this one. 173 00:12:50,290 --> 00:12:55,330 One, two, three, four and five will be will be discarded because four and five, they are the common 174 00:12:55,330 --> 00:12:57,480 in my set one and my set two. 175 00:12:57,850 --> 00:13:02,230 But if you go for my set to minus my set, one will be getting this one. 176 00:13:02,240 --> 00:13:05,790 There is that eight, nine, six, seven and four and five will not be there. 177 00:13:06,340 --> 00:13:06,830 I next. 178 00:13:06,860 --> 00:13:11,680 Well we can do the same either using operator minus or using the method different. 179 00:13:11,730 --> 00:13:14,110 So it'll be getting the results accordingly. 180 00:13:16,700 --> 00:13:21,170 Now we are going for the semantic difference in close up semantic difference, the common element in 181 00:13:21,170 --> 00:13:22,280 case of semantic difference. 182 00:13:22,400 --> 00:13:24,260 Common elements will not be coming. 183 00:13:24,530 --> 00:13:26,850 So now we do for the semantic difference. 184 00:13:26,850 --> 00:13:29,190 We'll be going for this Apakan it. 185 00:13:29,420 --> 00:13:36,440 So this is a symbol Apakan it so also known as hat, so that you can go for this operator Arpad correct 186 00:13:36,440 --> 00:13:38,960 or symmetric underscored difference. 187 00:13:38,980 --> 00:13:39,990 So there is another method. 188 00:13:40,490 --> 00:13:46,120 So here you can see that all the elements are out there, but only the common elements which are common. 189 00:13:46,130 --> 00:13:49,070 There is a four and five between Mindset one and Mindset two. 190 00:13:49,310 --> 00:13:55,310 They are not coming after doing the symmetric difference between my set one and my two. 191 00:13:56,800 --> 00:13:58,820 Now we are going for this membership check. 192 00:13:59,200 --> 00:14:02,230 So now here we are having one set is defined. 193 00:14:02,230 --> 00:14:06,280 That is a mind set, one, two in my set, one that is quite obvious. 194 00:14:06,280 --> 00:14:10,660 True, because two is one of the elements, one one of the members of this mindset, one. 195 00:14:10,810 --> 00:14:12,630 So our coming to a through here. 196 00:14:12,850 --> 00:14:15,250 So six in mind set one six is not there. 197 00:14:15,250 --> 00:14:17,290 The outcome is false too. 198 00:14:17,320 --> 00:14:18,280 Not in mind. 199 00:14:18,280 --> 00:14:18,810 Set one. 200 00:14:18,820 --> 00:14:24,040 So that is producing outcome false because two is there and six not in my set. 201 00:14:24,040 --> 00:14:25,680 One, its outcome is true here. 202 00:14:26,440 --> 00:14:33,560 Now we are going for this either iterating through a set so for later in set will come later. 203 00:14:33,670 --> 00:14:37,930 So in this way you can find that for each and every iteration we are picking up one of the characters 204 00:14:38,200 --> 00:14:39,310 from the string welcome. 205 00:14:39,460 --> 00:14:40,930 And that is getting printed. 206 00:14:42,750 --> 00:14:49,680 Now we are having some inbuilt functions with the set, so they are nothing but Lenn Max mentioned it 207 00:14:50,160 --> 00:14:54,360 so denote the number of elements we can have six elements in mind set one. 208 00:14:55,050 --> 00:14:59,620 So Leontes lane sprinting six eight, Maxus bending the maximum element. 209 00:14:59,820 --> 00:15:03,870 Here it is, five minutes bending the minimum element of the set members. 210 00:15:04,080 --> 00:15:11,820 It is sprinting zero at the shortest Misato will print set in the shortest form and outcome is of the 211 00:15:11,820 --> 00:15:12,540 type of list. 212 00:15:13,390 --> 00:15:14,880 But having this frozen set. 213 00:15:15,210 --> 00:15:22,050 So Biton frozen set frozen set is a new class that has the characteristic of a set, but its elements 214 00:15:22,050 --> 00:15:24,010 cannot be changed once assigned. 215 00:15:24,390 --> 00:15:29,780 So while tables are immutable, lists and frozen sets are imitable sets here. 216 00:15:29,940 --> 00:15:33,420 So we cannot do any kind of update and change on this frozen set. 217 00:15:33,810 --> 00:15:39,220 So we know that tuples are the imitable lists and frozen assets are imitable sets here. 218 00:15:39,600 --> 00:15:42,170 So here you have defined to frozen set. 219 00:15:42,180 --> 00:15:48,610 That is a mindset, one on my set to define them and then we are going to print them so the values are 220 00:15:48,750 --> 00:15:49,220 printed. 221 00:15:49,230 --> 00:15:55,260 You can find that when I'm printing this mindset one, it is getting printed as the set and here we 222 00:15:55,260 --> 00:15:56,400 are having the first brackets. 223 00:15:56,400 --> 00:15:58,730 Then within that we're having this calibrations. 224 00:15:58,740 --> 00:15:59,880 That is a set is there? 225 00:16:00,540 --> 00:16:03,520 And then we're going for this difference so different. 226 00:16:03,600 --> 00:16:05,880 My set one different mindset too. 227 00:16:06,240 --> 00:16:11,820 We can get this one and two because one and two will be the elements which will be which will be there 228 00:16:11,820 --> 00:16:16,620 as outcome three and four will be deleted because three and four are the common elements between this 229 00:16:16,620 --> 00:16:18,150 Mindset one and mindset two. 230 00:16:18,510 --> 00:16:19,740 We're going to go for the union. 231 00:16:19,740 --> 00:16:21,300 We're getting this outcome like this. 232 00:16:21,480 --> 00:16:22,950 We are going for the intersection. 233 00:16:23,130 --> 00:16:25,530 Only the common elements are coming also to unfold. 234 00:16:25,740 --> 00:16:27,480 We're going to go for the Semitic difference. 235 00:16:27,480 --> 00:16:32,040 Only three and four will get discarded and race elements will be there in the frozen set. 236 00:16:32,580 --> 00:16:36,270 But if I want to do some addition, if I do addition of a new element. 237 00:16:36,390 --> 00:16:39,870 So in that case, in case of frozen set, it will produce error. 238 00:16:39,870 --> 00:16:42,850 And this error is known as the attribute error proteins. 239 00:16:42,860 --> 00:16:44,760 Set object has no attribute. 240 00:16:44,760 --> 00:16:51,510 And so that's why this is the respective error we are facing, because a frozen set is nothing but a 241 00:16:51,510 --> 00:16:53,750 module version of a set here. 242 00:16:54,090 --> 00:16:59,610 So in this our discussion, in our discussion, we have gone through different operations on sets. 243 00:16:59,670 --> 00:17:04,650 We have shown what are the different abled functions, how to define and set, what can be done, what 244 00:17:04,650 --> 00:17:05,400 cannot be done. 245 00:17:05,610 --> 00:17:08,820 And we have discussed everything with some examples here. 246 00:17:09,240 --> 00:17:10,470 Thanks for watching this video.