1 00:00:00,330 --> 00:00:05,670 In this situation, we are discussing Python Dictionary, so what is the Python dictionary and how to 2 00:00:05,670 --> 00:00:06,460 define that one? 3 00:00:06,750 --> 00:00:10,530 What are the different methods we can apply on this Python dictionary? 4 00:00:10,630 --> 00:00:12,450 We'll be discussing that, run into details. 5 00:00:14,630 --> 00:00:22,190 In Python Dictionary is an unordered collection of items, while other compound types have only value 6 00:00:22,310 --> 00:00:23,410 as an element. 7 00:00:23,780 --> 00:00:28,230 A dictionary has a key value pairs, so that is a very important one. 8 00:00:28,610 --> 00:00:30,470 So we had a discussion on leaves. 9 00:00:30,500 --> 00:00:32,000 We had a discussion on table. 10 00:00:32,010 --> 00:00:36,610 We had a discussion on set that is so that we are having multiple different elements. 11 00:00:36,630 --> 00:00:42,500 Are there they may be or may not be of the same or different data types, but here we are finding this 12 00:00:42,500 --> 00:00:48,890 dictionary is quite different from those those data types, because here in the dictionary we are having 13 00:00:48,890 --> 00:00:55,390 the key value pair dictionaries are optimized to retrieve values when the key is known. 14 00:00:55,550 --> 00:01:01,400 So if you know the key, if you pass the key as argument, we can retrieve that respective value against 15 00:01:01,400 --> 00:01:06,210 the key which has been stored, stored onto the dictionary object. 16 00:01:06,590 --> 00:01:10,290 So here you are considered one that is a my dict one. 17 00:01:10,520 --> 00:01:13,650 So this is a variable which is containing one colon red. 18 00:01:14,210 --> 00:01:15,920 So what is one that is a key. 19 00:01:16,200 --> 00:01:17,870 What is the value that is read. 20 00:01:18,140 --> 00:01:19,480 Is read is a string. 21 00:01:19,490 --> 00:01:19,930 Yes. 22 00:01:20,090 --> 00:01:22,220 So it should be enclosed within single codes. 23 00:01:22,520 --> 00:01:27,730 And here this key value pair must be separated by this colon then come up. 24 00:01:27,740 --> 00:01:31,490 So we are having the second member, having the third member and so on. 25 00:01:31,610 --> 00:01:36,030 And each and every member is nothing but key value pair. 26 00:01:36,620 --> 00:01:38,420 So we are having this Maidique two. 27 00:01:38,450 --> 00:01:40,010 So here we are having this name. 28 00:01:40,910 --> 00:01:42,430 So there is one member here. 29 00:01:42,650 --> 00:01:49,820 So so H Colon thirty five addressed colon in this way that things have got represented. 30 00:01:51,380 --> 00:01:56,180 So here you are having the different methods which you can carry out on a dictionary. 31 00:01:56,360 --> 00:02:05,150 So the first one is a clear remove all items from the dictionary copy, return a copy of the dictionary, 32 00:02:05,480 --> 00:02:07,250 then from keys. 33 00:02:07,250 --> 00:02:11,220 So sequence within third decade, we're putting this come up. 34 00:02:11,420 --> 00:02:18,320 So return a new dictionary with keys from the sequence and the value equal to be default to none here. 35 00:02:18,680 --> 00:02:23,960 So in this way you are also having the get key within the third week we're having B here. 36 00:02:24,050 --> 00:02:25,880 So return the value of key. 37 00:02:26,030 --> 00:02:32,090 If the key does not exist except then return D and default is to none. 38 00:02:32,240 --> 00:02:34,910 So in this way we are getting this one. 39 00:02:35,180 --> 00:02:37,350 So let's consider this one as exist. 40 00:02:37,640 --> 00:02:44,790 So now this is my items so written in new view of the dictionaries items, that is a key and value. 41 00:02:45,020 --> 00:02:49,700 So these are the different methods are there and the respective descriptions we have given. 42 00:02:49,940 --> 00:02:56,150 You can go to them because actually are having a plan to show you all these methods, which are very 43 00:02:56,150 --> 00:03:01,360 much useful in our in our python programming, in our life demonstration there. 44 00:03:02,000 --> 00:03:07,250 So let us go for the demonstration, for the better understanding that how this method going can be 45 00:03:07,250 --> 00:03:11,300 used on our dictionary objects and what are the results we are getting. 46 00:03:11,540 --> 00:03:13,130 So here is a demonstration for you. 47 00:03:13,820 --> 00:03:20,350 Python Dictionary is an unordered collection of items, and while other compound types have only the 48 00:03:20,390 --> 00:03:26,540 value as an element, but in case of dictionary, it will be having our key loopier and dictionaries 49 00:03:26,540 --> 00:03:30,150 are optimized to the values when the key is known to us. 50 00:03:30,620 --> 00:03:35,090 So let us go for one creation of a of a dictionary here. 51 00:03:35,870 --> 00:03:38,710 So new dict is equal to one colon. 52 00:03:39,110 --> 00:03:42,200 So here one is the key and values the value. 53 00:03:42,770 --> 00:03:45,890 And you say colon is the respective separator between the key. 54 00:03:45,890 --> 00:03:52,190 And so these key envelopes would be separated by this comma and the whole thing must be enclosed within, 55 00:03:52,190 --> 00:03:55,120 Culebra says, as if it is a set Inca's upset. 56 00:03:55,130 --> 00:04:01,580 Also, we had all the set elements are to be enclosed within Culebras, but here in this upset, we 57 00:04:01,700 --> 00:04:04,670 only have the elements here, members there. 58 00:04:04,670 --> 00:04:08,470 But here in the dictionary will be having our key value pair. 59 00:04:09,050 --> 00:04:10,090 So print Newdegate. 60 00:04:10,150 --> 00:04:11,830 So now they can go for the execution. 61 00:04:11,840 --> 00:04:18,400 You can find that we're just printing this this particular dictionary and then print Newdegate. 62 00:04:18,410 --> 00:04:21,520 So this outcome has some print Newdegate one. 63 00:04:21,530 --> 00:04:23,550 So we are given one means a key value. 64 00:04:23,660 --> 00:04:25,190 So here we are having the skite. 65 00:04:25,520 --> 00:04:28,460 So the respective value will be so has got printed. 66 00:04:28,880 --> 00:04:34,460 If you go for this get and if you get two, then two is the key here and the value will be high. 67 00:04:34,460 --> 00:04:35,740 So high has got printed. 68 00:04:36,080 --> 00:04:42,200 So now you might be asking me what is the difference between this new DECT one and Newdegate get to 69 00:04:42,500 --> 00:04:42,770 here. 70 00:04:42,770 --> 00:04:51,050 The difference is that if you keep some if you keep some illegal or non-existent key here, so 10 is 71 00:04:51,050 --> 00:04:51,960 not there at present. 72 00:04:52,070 --> 00:04:55,770 So if hagwon execution, then I can find that key error is coming. 73 00:04:56,330 --> 00:04:57,860 So here is the key. 74 00:04:57,920 --> 00:05:02,870 The value, whatever we are giving it, the respective key is not existent here. 75 00:05:02,870 --> 00:05:04,870 We are getting one error that is accurate. 76 00:05:05,360 --> 00:05:06,380 Key error 10. 77 00:05:07,460 --> 00:05:09,150 So that is that issue. 78 00:05:09,170 --> 00:05:12,330 But in this case, if I put one in key here. 79 00:05:12,680 --> 00:05:15,110 So here you can find that it is returning none. 80 00:05:15,140 --> 00:05:16,070 It is returning none. 81 00:05:16,100 --> 00:05:21,890 So that is a basic difference between these two respective statements that is printed new one and print 82 00:05:21,890 --> 00:05:23,420 Newdegate get. 83 00:05:23,960 --> 00:05:30,790 So if we give, Dufka says, the valid key in that case, I'm getting this Halleran high, as I explained, 84 00:05:31,220 --> 00:05:34,630 updating Peloso for the new dict one I'm putting here. 85 00:05:34,670 --> 00:05:40,250 So now we see for this one, for this against this key, the value has got updated from hello to here. 86 00:05:40,700 --> 00:05:42,650 So now we are having this adding value. 87 00:05:42,660 --> 00:05:45,910 So that is a new dict for is the amnesty. 88 00:05:45,940 --> 00:05:50,540 Now here you can find that here Dysport is not existing here. 89 00:05:50,550 --> 00:05:55,660 So a new respective people loopier will be inserted in this dictionary. 90 00:05:58,590 --> 00:06:00,230 Now creating a new dictionary. 91 00:06:00,300 --> 00:06:05,370 So let me go for the executions of green squares, their respective values are getting printed. 92 00:06:05,730 --> 00:06:07,890 So now remove a particular item. 93 00:06:08,130 --> 00:06:11,110 So we are going for squares DOT four. 94 00:06:11,160 --> 00:06:13,520 So as of key is given directly for four. 95 00:06:13,740 --> 00:06:19,140 So that means for on 16, this particular this key value will be deleted. 96 00:06:19,360 --> 00:06:22,940 And that's why you it is returning the value at first 16. 97 00:06:22,970 --> 00:06:26,910 And you can find that, that for colon 16 that gives loopier is missing. 98 00:06:26,950 --> 00:06:29,130 Now remove an arbitrary item. 99 00:06:29,130 --> 00:06:30,520 You can go for this item. 100 00:06:30,540 --> 00:06:34,390 So in this case, a pop item, one arbitrary item will be deleted. 101 00:06:34,620 --> 00:06:38,810 So here you can find that five Gomaa 25, it has got deleted. 102 00:06:38,910 --> 00:06:42,810 So the respective value is not is now not existing. 103 00:06:43,260 --> 00:06:44,580 Delete a particular item. 104 00:06:44,580 --> 00:06:47,140 We can go for this deal and in square one. 105 00:06:47,400 --> 00:06:49,850 So this particular key value will be deleted. 106 00:06:50,010 --> 00:06:54,030 So we are remaining with this two column four and three colon nine here. 107 00:06:56,900 --> 00:07:01,820 Here we have defined one new dictionary, there's a square, so squares have got printed. 108 00:07:01,850 --> 00:07:04,360 Now we are going for these squares to clear. 109 00:07:04,490 --> 00:07:07,540 So it removes all the all the developers. 110 00:07:07,850 --> 00:07:09,220 So remove old items. 111 00:07:09,260 --> 00:07:13,310 And now if you print this square, it is printing that empty dictionary. 112 00:07:13,700 --> 00:07:15,880 So delete the dictionary itself. 113 00:07:15,890 --> 00:07:19,100 In that case, if in that case will be going Fadell Square. 114 00:07:19,430 --> 00:07:24,980 But after that, if you want to print squares as the squares have got deleted, so it will produce one 115 00:07:24,980 --> 00:07:26,300 error that is a nimura. 116 00:07:26,540 --> 00:07:27,500 So there is a numeric. 117 00:07:27,520 --> 00:07:32,330 So name squares is not defined because we have used this deal here. 118 00:07:32,570 --> 00:07:37,040 So that full declaration of the dictionary itself will get deleted. 119 00:07:41,420 --> 00:07:47,750 Next one, creating a new dictionary, using comprehension so we can find that X in range six, that 120 00:07:47,750 --> 00:07:51,510 means X will be ranging from zero to five because X will be exclusive. 121 00:07:51,920 --> 00:07:54,260 So zero, one, two, three, four, five. 122 00:07:54,290 --> 00:07:56,570 So these are the six values for X. 123 00:07:56,960 --> 00:07:59,630 So we are creating a dictionary that is Escalon. 124 00:07:59,630 --> 00:08:02,280 X will be the key and the value will be XRX. 125 00:08:02,570 --> 00:08:08,330 So now in this case, if I bring the squares, I'm getting the zero zero square and then one one squared 126 00:08:08,450 --> 00:08:11,570 and then two is the key and the value will be two square three is the key. 127 00:08:11,580 --> 00:08:15,480 There will be three square in the square, up to five colon twenty five. 128 00:08:16,070 --> 00:08:17,180 So we are getting this. 129 00:08:17,390 --> 00:08:19,490 So dictionary membership test. 130 00:08:19,790 --> 00:08:22,260 So how to do the membership test here. 131 00:08:22,280 --> 00:08:25,680 So here in this case we discuss only the dictionary using comprehension. 132 00:08:26,030 --> 00:08:29,700 Now it is a and here you'll be going for the testing of the membership. 133 00:08:30,050 --> 00:08:35,090 So one dictionary has got a defined so name of the dictionary is square. 134 00:08:35,570 --> 00:08:37,150 So now one in square. 135 00:08:37,160 --> 00:08:38,790 So one this key is present. 136 00:08:39,020 --> 00:08:41,120 So one in squares will be giving us. 137 00:08:41,120 --> 00:08:45,980 True, because we are testing the membership of this one as a key in this dictionary. 138 00:08:46,460 --> 00:08:48,020 Do not in square. 139 00:08:48,020 --> 00:08:49,260 You see the two is not there. 140 00:08:49,430 --> 00:08:56,930 So two not in square will produce the outcome through here, but print at 49 in square 49 as a key is 141 00:08:56,930 --> 00:08:57,660 not present here. 142 00:08:57,860 --> 00:08:59,690 So that's why it is returning the value. 143 00:08:59,700 --> 00:09:01,610 It is returning the boolean value. 144 00:09:01,610 --> 00:09:02,360 That is false. 145 00:09:03,560 --> 00:09:09,230 So here, whatever you are passing, whatever you were mentioning, they are the key that we are not 146 00:09:09,230 --> 00:09:09,770 considering. 147 00:09:09,770 --> 00:09:13,860 This 49, which is present as a value as a key 49, is absent. 148 00:09:13,900 --> 00:09:16,700 So print 49 in squares, it is returning. 149 00:09:16,700 --> 00:09:17,570 The value falls. 150 00:09:20,030 --> 00:09:26,300 Now we are going for this iterating through a dictionary, so square one on one three nine five point 151 00:09:26,300 --> 00:09:27,670 twenty five, we define this one. 152 00:09:27,980 --> 00:09:33,380 So for I in squares, so print squares, I so you can go for the execution. 153 00:09:33,380 --> 00:09:37,130 You can find that we are printing this one nine, 25, 14. 154 00:09:37,130 --> 00:09:39,100 And so they are all the values. 155 00:09:39,380 --> 00:09:45,680 So here this guy has been treated as a key, so respected value has been popped out and has been retrieved 156 00:09:45,680 --> 00:09:48,040 and they have got printed in this iteration. 157 00:09:48,560 --> 00:09:53,120 So we are finding out there is there is a square is one dictionary here. 158 00:09:53,330 --> 00:09:53,960 We're going to the. 159 00:09:54,440 --> 00:09:56,980 So these are the inbuilt functions in a dictionary. 160 00:09:57,320 --> 00:09:59,410 So Lin will print the length of the dictionary. 161 00:09:59,420 --> 00:10:01,250 That means that a number of key value pairs. 162 00:10:01,460 --> 00:10:06,920 So here you are printing this one is five because one, two, three, four, five key value pairs of 163 00:10:06,920 --> 00:10:09,130 their print chocolate squares. 164 00:10:09,230 --> 00:10:13,210 So you can find that the respective key values, they have become sorted. 165 00:10:13,400 --> 00:10:14,510 They have become sorted here. 166 00:10:14,870 --> 00:10:20,840 So in this way, we are having some inbuilt methods that are inbuilt functions, that they are building 167 00:10:20,840 --> 00:10:24,900 functions, that they are in a dictionary that can be applied on the dictionary objects. 168 00:10:25,340 --> 00:10:30,800 So in this discussion, we have a detailed discussion that how to create a dictionary and what are the 169 00:10:30,800 --> 00:10:35,630 different permitted and not permitted operations that we can carry out on a dictionary? 170 00:10:35,930 --> 00:10:38,270 I think now the conception is getting clear to you. 171 00:10:38,810 --> 00:10:40,070 Thanks for watching this video.