1 00:00:00,440 --> 00:00:03,120 Indecision, we are discussing Biton Dictionary. 2 00:00:03,690 --> 00:00:06,510 So what is a Python dictionary and how do define that one? 3 00:00:06,840 --> 00:00:10,560 What are the different methods we can play on this Python dictionary? 4 00:00:10,680 --> 00:00:12,480 We'll be discussing that point into details. 5 00:00:14,720 --> 00:00:21,650 In Python Dictionary is an unordered collection of items, while other compound data types have only 6 00:00:21,650 --> 00:00:23,420 value as an element. 7 00:00:24,020 --> 00:00:28,220 Addiction has a key value pair, so that is a very important one. 8 00:00:28,670 --> 00:00:30,440 So we had a discussion on leads. 9 00:00:30,530 --> 00:00:32,030 We had a discussion on top of that. 10 00:00:32,030 --> 00:00:36,620 We had a discussion on set that is saw that we are having multiple different elements. 11 00:00:36,620 --> 00:00:37,070 Are there? 12 00:00:37,280 --> 00:00:40,220 They may be or may not be of the same or different data types. 13 00:00:40,610 --> 00:00:47,330 But here we are finding this dictionary is quite different from those those data types because he didn't 14 00:00:47,330 --> 00:00:48,260 get a dictionary. 15 00:00:48,390 --> 00:00:55,410 Well, having the key value pair dictionaries are optimized to return values when the key is not. 16 00:00:55,640 --> 00:01:01,400 So if we know the key, if we pass the key as argument, we can retrieve the respective value against 17 00:01:01,400 --> 00:01:06,200 the key which has been stored restored onto the dictionary object. 18 00:01:06,650 --> 00:01:08,570 So here you have considered one. 19 00:01:08,890 --> 00:01:10,340 Is a my dict one. 20 00:01:10,580 --> 00:01:11,550 So this is a variable. 21 00:01:11,670 --> 00:01:13,690 We're just containing one colon grade. 22 00:01:14,270 --> 00:01:15,950 So what is one that is a key. 23 00:01:16,250 --> 00:01:17,090 What is a value. 24 00:01:17,150 --> 00:01:19,460 That is a raid is red is a string. 25 00:01:19,520 --> 00:01:19,970 Yes. 26 00:01:20,150 --> 00:01:22,250 So it should be enclosed within signal codes. 27 00:01:22,640 --> 00:01:26,690 And here this key value pierde must be separated by this kolon. 28 00:01:27,020 --> 00:01:31,460 Then come up so that we are having the second member and having the third member and so on. 29 00:01:31,700 --> 00:01:35,990 And each and every member is nothing but key value pair. 30 00:01:36,680 --> 00:01:38,420 So we are having this my deck too. 31 00:01:38,480 --> 00:01:40,720 So here we are having this name treated. 32 00:01:40,970 --> 00:01:42,440 So there is a one member here. 33 00:01:42,710 --> 00:01:44,840 So comma H Colon 35. 34 00:01:45,200 --> 00:01:46,800 Address Colon Calcutta. 35 00:01:46,940 --> 00:01:49,780 In this way that things have got represented. 36 00:01:51,410 --> 00:01:56,210 So here you are having the different mythos, which you can carry out on the community. 37 00:01:56,420 --> 00:02:01,100 So the first one is a clear remove all items from the dictionary. 38 00:02:01,460 --> 00:02:02,000 Copy. 39 00:02:02,120 --> 00:02:07,150 Return is hand a copy of the dictionary, then form keys. 40 00:02:07,310 --> 00:02:11,030 So sequins within third bucket were putting this come up. 41 00:02:11,030 --> 00:02:18,050 Be so written, a new dictionary with keys from the sequence and the Ballew equal Dupee default to none 42 00:02:18,050 --> 00:02:18,290 here. 43 00:02:18,740 --> 00:02:23,990 So in this way you are also having the get key within the third and we're having B here. 44 00:02:24,110 --> 00:02:25,950 So return the value of key. 45 00:02:26,150 --> 00:02:29,870 If the key does not exist a exit then written D. 46 00:02:30,140 --> 00:02:32,150 And default is to none. 47 00:02:32,300 --> 00:02:34,910 So in this way we are getting this one. 48 00:02:35,220 --> 00:02:37,370 So let's consider this one as exist. 49 00:02:37,700 --> 00:02:39,450 So now this is my items. 50 00:02:39,740 --> 00:02:43,420 So written in new view of the dictionaries items. 51 00:02:43,640 --> 00:02:44,780 That is a key and value. 52 00:02:45,080 --> 00:02:49,760 So these are the different methods that there and the respective descriptions were given. 53 00:02:50,030 --> 00:02:55,970 You can go to them because actually you are having a plan to show you all these methods, which are 54 00:02:55,970 --> 00:03:01,160 very much usable in our in our python programming, in our life demonstration. 55 00:03:02,060 --> 00:03:08,210 So let us go for the demo session for the better understanding that how this method can be used on our 56 00:03:08,210 --> 00:03:11,300 dictionary objects and what other reasons we're getting. 57 00:03:11,600 --> 00:03:13,090 So here is a demonstration for you. 58 00:03:13,940 --> 00:03:17,420 Biton Disunity is an unordered collection of items. 59 00:03:17,810 --> 00:03:21,560 And while other compounder types have only the value as an element. 60 00:03:21,890 --> 00:03:27,530 But in guessable dictionary, we'll be having our key polu peer and dictionaries are optimized to the 61 00:03:27,530 --> 00:03:28,190 two values. 62 00:03:28,370 --> 00:03:30,170 When the key is known to us. 63 00:03:30,650 --> 00:03:35,060 So let us go for one creation of a of a dictionary here. 64 00:03:35,900 --> 00:03:38,590 So new dict is equal to one kolon. 65 00:03:38,750 --> 00:03:39,080 Hello. 66 00:03:39,140 --> 00:03:42,200 So here one is the key and Hallowes the value. 67 00:03:42,860 --> 00:03:46,290 And you see Colan is the respective separator between the Key and Peele. 68 00:03:46,790 --> 00:03:52,190 So this Key and Peele appears to be separated by this comma and the whole thing must be included within, 69 00:03:52,190 --> 00:03:55,090 Culebra says, as if it is a set in upset. 70 00:03:55,150 --> 00:04:00,770 Also, we had all the same set elements are to be interested in culebras this, but here it gets upset. 71 00:04:01,340 --> 00:04:04,640 We only have the element zikr members there. 72 00:04:04,670 --> 00:04:08,420 But here in the case of dictionary, we'll be having a key value pair. 73 00:04:09,110 --> 00:04:10,060 So print new deck. 74 00:04:10,130 --> 00:04:11,810 So now let go for the execution. 75 00:04:11,870 --> 00:04:14,150 You can find that by just printing this. 76 00:04:14,450 --> 00:04:18,360 This particular dictionary and then print Newdegate. 77 00:04:18,470 --> 00:04:19,700 So this outcome has come. 78 00:04:20,300 --> 00:04:21,470 Print new dict one. 79 00:04:21,530 --> 00:04:22,310 So we are given. 80 00:04:22,430 --> 00:04:23,280 One means a key. 81 00:04:23,400 --> 00:04:23,550 Hello. 82 00:04:23,720 --> 00:04:25,130 So here we are having this key. 83 00:04:25,580 --> 00:04:27,120 So the respective value will be held. 84 00:04:27,230 --> 00:04:28,420 So Hellam has got printed. 85 00:04:28,940 --> 00:04:30,250 If you go for this get. 86 00:04:30,590 --> 00:04:33,260 And if you give two, then two is the key here. 87 00:04:33,500 --> 00:04:34,460 And the value will be high. 88 00:04:34,460 --> 00:04:35,750 So high has got printed. 89 00:04:36,110 --> 00:04:41,870 So now it might be asking me what is the difference between this new DECT one and new dict up, get 90 00:04:41,870 --> 00:04:42,760 two here. 91 00:04:42,770 --> 00:04:50,240 The difference is that if you keep some if you keep some illegal or say non existent key here. 92 00:04:50,450 --> 00:04:51,950 So 10 is not there at present. 93 00:04:52,130 --> 00:04:55,730 So if I go on execution, then I can find that key error is coming. 94 00:04:56,390 --> 00:04:59,690 So here is the key, the value part of what we are giving it. 95 00:05:00,140 --> 00:05:02,830 The respective key is not existent here. 96 00:05:02,870 --> 00:05:03,980 We are getting one error. 97 00:05:04,040 --> 00:05:04,850 That is a key error. 98 00:05:05,210 --> 00:05:06,210 So key error can. 99 00:05:07,520 --> 00:05:09,080 So that is that issue. 100 00:05:09,200 --> 00:05:12,350 But in this case, if I put one in pallette key here. 101 00:05:12,740 --> 00:05:15,020 So here you can find that it is returning none. 102 00:05:15,170 --> 00:05:16,000 It is returning none. 103 00:05:16,100 --> 00:05:19,460 So that is a basic difference between these two respective statements. 104 00:05:19,490 --> 00:05:20,880 That is print new one. 105 00:05:21,320 --> 00:05:22,760 And print new dict dark. 106 00:05:22,970 --> 00:05:23,420 Get. 107 00:05:24,020 --> 00:05:30,800 So if we give what Dukkha says the valid key in that case, I'm getting this Halloween high as a explained 108 00:05:31,310 --> 00:05:31,980 operating value. 109 00:05:32,050 --> 00:05:34,610 So for the new dict one I'm putting here. 110 00:05:34,700 --> 00:05:36,420 So now you see for this one. 111 00:05:36,460 --> 00:05:37,700 For this against this key. 112 00:05:37,730 --> 00:05:40,190 The value has got updated from hello to here. 113 00:05:40,760 --> 00:05:42,630 So now we are having this adding value. 114 00:05:42,650 --> 00:05:45,890 So that is a new dict for is the normal state. 115 00:05:45,920 --> 00:05:50,510 Now here you can find that here this fall is not existing here. 116 00:05:50,540 --> 00:05:55,670 So a new respective keep her loopier will be inserted in this dictionary. 117 00:05:58,680 --> 00:06:00,120 Now creating a new dictionary. 118 00:06:00,330 --> 00:06:02,280 So, Nick, let me go for the execution. 119 00:06:02,390 --> 00:06:05,370 So print squares, the respective values are getting printed. 120 00:06:05,790 --> 00:06:07,920 So now remove a particular item. 121 00:06:08,220 --> 00:06:11,100 So we are going for squares, dot, pop four. 122 00:06:11,190 --> 00:06:13,510 So as of key is given radically for. 123 00:06:13,800 --> 00:06:15,500 So that means for column sixteen. 124 00:06:16,020 --> 00:06:19,140 This particular this give a loopier will be deleted. 125 00:06:19,470 --> 00:06:22,120 And that's why you it is returning the value at first. 126 00:06:22,120 --> 00:06:22,850 So 16. 127 00:06:23,070 --> 00:06:27,160 And you can find that, that for column sixteen that give her loopier is missing now. 128 00:06:27,730 --> 00:06:29,110 Remove an arbitrary item. 129 00:06:29,110 --> 00:06:30,510 We can go for this pop item. 130 00:06:30,570 --> 00:06:34,410 So in this case, a pop item, one arbitrary item will be deleted. 131 00:06:34,680 --> 00:06:37,760 So here you can find that five comma twenty five. 132 00:06:37,860 --> 00:06:38,770 It has got delegate. 133 00:06:38,970 --> 00:06:42,780 So the respective key value Peate is not is now not existing. 134 00:06:43,260 --> 00:06:44,550 Delete a particular item. 135 00:06:44,560 --> 00:06:47,120 We can go for this deal and then square one. 136 00:06:47,460 --> 00:06:49,830 So this particular Keever loopier will be deleted. 137 00:06:50,100 --> 00:06:54,000 So we are remaining with this two column four and three Kolon nine here. 138 00:06:56,960 --> 00:06:57,860 Here we have defined. 139 00:06:57,940 --> 00:06:59,480 One new dictionary. 140 00:06:59,530 --> 00:07:00,230 There's a square. 141 00:07:00,260 --> 00:07:01,790 So squares have got printed. 142 00:07:01,880 --> 00:07:04,370 Now we are going for these squares are clear. 143 00:07:04,580 --> 00:07:07,550 So it removes all the all the key value pairs. 144 00:07:07,880 --> 00:07:09,200 So remove all the items. 145 00:07:09,380 --> 00:07:13,310 And now if we print this square, it is printing the empty dictionary. 146 00:07:13,730 --> 00:07:15,830 So delete the dictionary itself. 147 00:07:15,920 --> 00:07:19,220 In that case, if in that case we'll be going for dayle squares. 148 00:07:19,490 --> 00:07:23,690 But after that, if you want to print squares as the squares have got deleted. 149 00:07:23,930 --> 00:07:25,270 So it would produce one error. 150 00:07:25,310 --> 00:07:26,190 That is a name error. 151 00:07:26,570 --> 00:07:27,500 So there is a name attached. 152 00:07:27,530 --> 00:07:32,300 So name squares is not defined because we have used this deal here. 153 00:07:32,630 --> 00:07:37,010 So the full declaration of the dictionary itself will get deleted. 154 00:07:41,480 --> 00:07:47,770 Next one, creating a new dictionary, using comprehension so you can find that X in range six, that 155 00:07:47,770 --> 00:07:51,530 means X will be ranging from zero to five because six will be exclusive. 156 00:07:51,980 --> 00:07:52,550 So zero. 157 00:07:52,610 --> 00:07:54,260 One, two, three, four, five. 158 00:07:54,290 --> 00:07:56,540 So these are the six values for X. 159 00:07:57,020 --> 00:08:02,330 So we are creating a dictionary that is X, Kolon X will be the key and the value will be X, star X. 160 00:08:02,630 --> 00:08:06,560 So now in this case, if I print the squares, I'm getting the zero zero squared. 161 00:08:06,830 --> 00:08:10,870 And then one one squared and then two is the key and the value will be two square. 162 00:08:10,910 --> 00:08:11,540 Three is the key. 163 00:08:11,570 --> 00:08:12,450 The value will be three square. 164 00:08:12,540 --> 00:08:14,780 In this way, up to five kolon. 165 00:08:14,800 --> 00:08:15,440 Twenty five. 166 00:08:16,130 --> 00:08:17,180 So we are getting this. 167 00:08:17,430 --> 00:08:19,500 So dictionary membership test. 168 00:08:19,850 --> 00:08:22,220 So how to do the membership test here. 169 00:08:22,280 --> 00:08:25,700 So here in this case, we discuss only the dictionary using comprehension. 170 00:08:26,090 --> 00:08:29,690 Now it is a I here will be going for the testing of the membership. 171 00:08:30,080 --> 00:08:33,040 So one dictionary has got defined. 172 00:08:33,290 --> 00:08:35,300 So the name of the dictionary is squares. 173 00:08:35,600 --> 00:08:37,100 So now one in squared. 174 00:08:37,170 --> 00:08:38,780 So one diski is present. 175 00:08:39,050 --> 00:08:41,120 So one in squares will be giving us. 176 00:08:41,120 --> 00:08:45,980 True, because we are testing the membership of this one as a key in this dictionary. 177 00:08:46,490 --> 00:08:47,980 Do not in square. 178 00:08:48,050 --> 00:08:49,250 You see, the two is not there. 179 00:08:49,490 --> 00:08:52,160 So two not in square will produce the outcome. 180 00:08:52,190 --> 00:08:52,730 True here. 181 00:08:53,240 --> 00:08:54,730 But print at 49. 182 00:08:54,830 --> 00:08:57,650 In squares 49 as a key is not present here. 183 00:08:57,890 --> 00:08:59,630 So that's why it is returning the value. 184 00:08:59,750 --> 00:09:01,600 It is returning the boolean value. 185 00:09:01,610 --> 00:09:02,420 That is a false. 186 00:09:03,620 --> 00:09:05,940 So here what do we are passing by dividing. 187 00:09:05,980 --> 00:09:06,920 You were mentioning Bellwether. 188 00:09:07,090 --> 00:09:13,260 They are the key that Akif we're not considering this 49, which is present as a value as a key 49, 189 00:09:13,280 --> 00:09:13,850 is absent. 190 00:09:13,880 --> 00:09:17,570 So putting 49 in squares, it is returning the value falls. 191 00:09:20,080 --> 00:09:22,850 Now we are going for this iterating through a dictionary. 192 00:09:23,170 --> 00:09:26,820 So squares one Kolon one three nine five 125 25. 193 00:09:26,920 --> 00:09:28,440 Define this one so far. 194 00:09:28,640 --> 00:09:29,810 I in squares. 195 00:09:30,110 --> 00:09:31,780 So print squares, eyes. 196 00:09:31,820 --> 00:09:33,380 So you can go for the execution. 197 00:09:33,380 --> 00:09:37,230 You can find that you are printing this one nine, 25, 49. 198 00:09:37,460 --> 00:09:39,110 So they are all the values. 199 00:09:39,440 --> 00:09:45,200 So here this I has been treated as a key, so respected value has been popped out and that has been 200 00:09:45,200 --> 00:09:48,050 retrieved and they have what printed in this iteration. 201 00:09:48,590 --> 00:09:53,120 So we are finding out that there is a there is a squared is one dictionary here. 202 00:09:53,400 --> 00:09:54,400 We're going for the Lynn. 203 00:09:54,440 --> 00:09:56,990 So these are the Inbal functions in a dictionary. 204 00:09:57,350 --> 00:09:59,390 So Lynn will print the length of the dictionary. 205 00:09:59,420 --> 00:10:01,280 That means a number of key value pairs. 206 00:10:01,520 --> 00:10:05,990 So here you are printing this one as five because one, two, three, four, five. 207 00:10:06,020 --> 00:10:07,200 Keep a loopier, Sadir. 208 00:10:07,700 --> 00:10:09,070 Print Shattuck's squares. 209 00:10:09,290 --> 00:10:13,220 So you can find that the respective P values, they have become shotted. 210 00:10:13,460 --> 00:10:14,510 They have become shorted here. 211 00:10:14,900 --> 00:10:20,840 So in this way, we're having some inbuilt methods that are inbuilt functions, that there are building 212 00:10:20,840 --> 00:10:24,920 functions, that there is nobody Kenly that can be applied on the dictionary objects. 213 00:10:25,370 --> 00:10:30,680 So in this discussion, we have a detailed discussion that how to create this dictionary and what are 214 00:10:30,680 --> 00:10:35,630 the department permitted and not permitted operations that we can carry out on a dictionary? 215 00:10:36,020 --> 00:10:38,270 I think now the conception is getting clear to you. 216 00:10:38,840 --> 00:10:40,040 Thanks for watching this video.