1 00:00:12,480 --> 00:00:20,040 Hello, everybody, so we now start discussing dictionaries and this will be the advanced part in the 2 00:00:20,040 --> 00:00:26,490 previous videos that we got familiar with dictionaries, and now we'll learn some more cool manipulations. 3 00:00:26,490 --> 00:00:33,630 We can apply on it and we will learn how to create a nested dictionary, will learn how to remove cells 4 00:00:33,630 --> 00:00:38,320 out of the dictionary, how to make a duplicate and many more cool stuff. 5 00:00:39,040 --> 00:00:48,120 So first one is line is how can we create a nested a dictionary with nested entities and what is nested 6 00:00:48,570 --> 00:00:49,300 for that? 7 00:00:49,530 --> 00:00:54,030 Let me open the explorer and what we can see here. 8 00:00:54,030 --> 00:00:55,800 For example, we have the C drive. 9 00:00:56,430 --> 00:01:03,270 OK, so there is a small arrow here and once I click it, I can see what's inside the C drive so I can 10 00:01:03,270 --> 00:01:10,900 address C as a parent can tie it is the parent of follower of the city of BitBucket and so on. 11 00:01:10,920 --> 00:01:15,350 C is the parent and these are the child entities inside it. 12 00:01:15,600 --> 00:01:19,590 So this would, this would be called a child and this is a parent. 13 00:01:19,920 --> 00:01:26,130 And if we click on audacity, so we have additional nested folders inside it. 14 00:01:26,130 --> 00:01:33,660 So off halp folder audacity is the parent, while help is the child of audacity. 15 00:01:34,470 --> 00:01:41,940 So this is this what nested means nested means you have inside the parent while you have items inside 16 00:01:41,940 --> 00:01:42,090 it. 17 00:01:43,690 --> 00:01:49,210 OK, so in previous lectures, we studied how to create a key value dictionary, which was simple, 18 00:01:49,570 --> 00:01:59,380 we just initiated we just declared a dictionary and then inside we put key value, key value items. 19 00:02:00,070 --> 00:02:03,870 Now let's try to learn how to create a nested dictionary. 20 00:02:04,240 --> 00:02:08,950 The dictionary will contain two or more layers on it, on each key. 21 00:02:09,980 --> 00:02:17,990 In other words, you can see here a nested dictionary, and it contains the following we have here. 22 00:02:18,440 --> 00:02:19,220 This is. 23 00:02:20,310 --> 00:02:26,520 A parent cell, and this is also a parent cell, because these are the like muscle cells. 24 00:02:27,090 --> 00:02:27,480 All right. 25 00:02:27,490 --> 00:02:33,880 This is the outside layer of dictionary, same as we have here, key value. 26 00:02:34,440 --> 00:02:37,170 So in this occasion, we have key. 27 00:02:39,050 --> 00:02:39,830 Value. 28 00:02:41,200 --> 00:02:41,770 Kee. 29 00:02:42,920 --> 00:02:50,000 Value, these are this is a parent cell and this is also a parent cell. 30 00:02:50,600 --> 00:02:56,140 OK, so we see that this day and we are kids of parents cells. 31 00:02:56,720 --> 00:03:04,340 And while David and Lisa are keys of an inner layer, which is the child cells. 32 00:03:05,120 --> 00:03:09,470 So let's see, what do I mean here? 33 00:03:10,310 --> 00:03:10,910 All right. 34 00:03:11,210 --> 00:03:12,540 So, mijo. 35 00:03:13,340 --> 00:03:13,940 All right. 36 00:03:14,210 --> 00:03:19,580 Joe is a Web automation developer, and this dictionary is about Joe. 37 00:03:20,990 --> 00:03:22,460 So we can see here. 38 00:03:22,490 --> 00:03:27,860 And Joe, we declared the dictionary and here we have the following. 39 00:03:28,160 --> 00:03:31,560 We have the key age and we have the value. 40 00:03:31,580 --> 00:03:32,390 Thirty five. 41 00:03:33,350 --> 00:03:37,140 And then we have a comma separator between two parent cells. 42 00:03:37,460 --> 00:03:41,940 This is the first cell what marked in green and this is the second cell. 43 00:03:42,170 --> 00:03:45,870 So we have here a key age thirty five. 44 00:03:46,160 --> 00:03:49,580 And here we have also a key, which is kids. 45 00:03:49,910 --> 00:03:53,300 And the value is what comes after the kids. 46 00:03:53,300 --> 00:04:04,010 All of this David boy, Lisa girl, all that part is one one big value that is attached to the kids 47 00:04:04,220 --> 00:04:04,620 key. 48 00:04:05,060 --> 00:04:13,790 OK, and once looking inside the kids value, you can see there additional nested cells. 49 00:04:14,030 --> 00:04:19,850 So inside that you can see David, which is a key and the value is a boy. 50 00:04:20,090 --> 00:04:28,140 And because the key of the both child cells, the key of them are kids. 51 00:04:28,310 --> 00:04:31,570 So here we are going to have some information about kids, obviously. 52 00:04:31,760 --> 00:04:36,100 So we have David, which is a boy, and this is child's cell one. 53 00:04:36,110 --> 00:04:37,040 It is nested. 54 00:04:37,490 --> 00:04:42,890 And we also have Lisa, which is a girl, and this is child cell two, which is also nested. 55 00:04:42,890 --> 00:04:44,870 They are both nested inside kids. 56 00:04:45,320 --> 00:04:47,300 So this is quite simple. 57 00:04:47,300 --> 00:04:55,190 If you get the hang of the rules here and it's pretty much the same, only you will drill down inside 58 00:04:55,910 --> 00:04:56,590 the cells. 59 00:04:56,990 --> 00:04:57,350 All right. 60 00:04:57,360 --> 00:05:04,830 So this is a good example to understand from for for the practice and follow following topics. 61 00:05:05,240 --> 00:05:06,940 OK, so it's pretty much the same. 62 00:05:06,980 --> 00:05:08,180 There's nothing new here. 63 00:05:08,480 --> 00:05:16,640 Just the difference is that until now we knew that we have QI, which is one certain string or a number, 64 00:05:16,790 --> 00:05:19,990 and we have a value, which is also a string number or boolean. 65 00:05:20,240 --> 00:05:29,210 And here in the kids, our value is not only one type of input, it has nested for inputs. 66 00:05:29,480 --> 00:05:32,390 So the value now has nested cells. 67 00:05:34,060 --> 00:05:43,120 OK, so coming to the next topic, which is related to the what we just learn how to extract a value 68 00:05:43,120 --> 00:05:45,620 bickie out of a nested dictionary. 69 00:05:46,180 --> 00:05:52,450 So we have learned in previous lectures that if you want to extract a value, for example, we have 70 00:05:52,660 --> 00:05:54,320 this dictionary once. 71 00:05:54,370 --> 00:05:58,080 We want to extract the H the H sale value. 72 00:05:58,270 --> 00:06:03,990 So I'll just mention the dictionary, then square brackets and put the key inside. 73 00:06:05,470 --> 00:06:11,630 And then once we apply it and print it out, the output is obviously going to be thirty two. 74 00:06:12,450 --> 00:06:15,110 OK, this one we have already learned. 75 00:06:15,260 --> 00:06:18,670 And now let's see how can we do it with nested. 76 00:06:19,120 --> 00:06:22,570 OK, so here we have an example for nested dictionary. 77 00:06:22,990 --> 00:06:23,560 All right. 78 00:06:25,780 --> 00:06:34,150 And let's see how it works with Nesto Dictionary, and once we need to extract the value out of a nested 79 00:06:34,150 --> 00:06:36,220 dictionary, we do it in the same way. 80 00:06:38,190 --> 00:06:46,770 Yeah, so we do it in the same way and the way to do it, if you want to extract a dictionary next, 81 00:06:46,770 --> 00:06:50,120 it says we should use their key, which is kids. 82 00:06:50,460 --> 00:06:50,840 Yeah. 83 00:06:51,210 --> 00:06:53,340 So if we have a dictionary here. 84 00:06:54,610 --> 00:07:04,690 And as we did here before, we wanted to extract the value of age, meaning 32, we just mentioned the 85 00:07:04,690 --> 00:07:08,070 dictionary have put the key inside square brackets. 86 00:07:08,230 --> 00:07:11,140 So here we are going to do just the same thing. 87 00:07:11,410 --> 00:07:14,350 We're just going to do Joey and then kids. 88 00:07:16,010 --> 00:07:27,470 And once we apply that, we can extract the values which are inside the value cell and we can't even 89 00:07:27,470 --> 00:07:29,900 go further and. 90 00:07:31,770 --> 00:07:33,810 Doing advanced example. 91 00:07:35,020 --> 00:07:37,270 Which will be the following. 92 00:07:41,000 --> 00:07:42,170 So what if. 93 00:07:46,050 --> 00:07:53,790 We want to just want to lose the mark yellow marker, so if we would like to extract. 94 00:07:55,940 --> 00:07:56,950 The value. 95 00:07:58,160 --> 00:08:00,110 Like the gender. 96 00:08:01,290 --> 00:08:06,270 Of David, how can we do it? 97 00:08:06,800 --> 00:08:16,590 OK, so the way to do it is, first of all, to extract the kids and then from inside the kids, we 98 00:08:16,590 --> 00:08:19,590 need to extract David, which is also the key. 99 00:08:19,770 --> 00:08:20,280 Correct. 100 00:08:20,730 --> 00:08:27,240 So once we apply this, it's like double extraction, we will get the output of. 101 00:08:29,170 --> 00:08:37,090 Boy, OK, so this is the way to do it if you want to extract the right part here right part, which 102 00:08:37,090 --> 00:08:44,500 is the value you just mentioned the kids key, if you want to extract the value of the inner cell, 103 00:08:44,740 --> 00:08:46,300 you mentioned this key. 104 00:08:46,630 --> 00:08:51,970 Once you mentioned this key, this is for your disposal and then you want to extract the boy. 105 00:08:51,990 --> 00:08:57,700 So you mentioned David, which is this key and then you will extract the boy value. 106 00:08:58,450 --> 00:09:00,540 OK, all right. 107 00:09:00,760 --> 00:09:07,400 So now let's see, how can we create a dictionary, which is a copy of an existing dictionary? 108 00:09:07,570 --> 00:09:13,900 Sometimes we want to make duplicate of our existing dictionary and we can achieve it by using the copy 109 00:09:13,900 --> 00:09:14,150 action. 110 00:09:15,040 --> 00:09:15,560 All right. 111 00:09:16,090 --> 00:09:19,150 So in a few seconds, we'll see how to do it. 112 00:09:19,960 --> 00:09:21,180 It's pretty simple. 113 00:09:21,910 --> 00:09:29,050 OK, you just declare a new dictionary, then you do equals and then you mention the old dictionary 114 00:09:29,050 --> 00:09:30,740 and use the DOT copy action. 115 00:09:31,360 --> 00:09:33,610 So now once we try to print. 116 00:09:34,920 --> 00:09:41,650 Joe, a new dictionary, we will see a printout of exactly what we have in the original dictionary. 117 00:09:42,510 --> 00:09:44,550 So this is how you duplicate the dictionary. 118 00:09:45,360 --> 00:09:50,010 And now, last but not least, basically it's not last. 119 00:09:50,130 --> 00:09:50,640 All right. 120 00:09:51,120 --> 00:09:55,380 So we have we we want now to delete a complete cell. 121 00:09:56,160 --> 00:09:59,340 We already encountered the pop action key in this. 122 00:09:59,580 --> 00:10:02,490 So we know how to delete cells in this. 123 00:10:02,790 --> 00:10:05,520 But let's see if it's the same in dictionaries. 124 00:10:06,030 --> 00:10:08,730 So we use pop action, same words do the lists. 125 00:10:08,880 --> 00:10:12,000 This will delete both key and value of the cell. 126 00:10:12,420 --> 00:10:23,080 This means that if we do the following thing, we address this dictionary and we use pop and put inside. 127 00:10:23,340 --> 00:10:27,850 OK, we put inside the key item inside the box. 128 00:10:28,170 --> 00:10:33,420 So once we apply this meaning, we want to remove this cell. 129 00:10:34,960 --> 00:10:42,120 Once we print Alex afterwards, after using Pop, we'll just lose the age and the 32 values which are 130 00:10:42,130 --> 00:10:49,060 key and value connected AM, and this way we will just delete them out of the dictionary. 131 00:10:50,940 --> 00:10:54,600 And now let's see, how can we add a new cell, for example? 132 00:10:54,630 --> 00:10:56,880 We would like to add a new cell to the dictionary. 133 00:10:57,300 --> 00:11:00,290 We have again, we have this one. 134 00:11:00,300 --> 00:11:01,680 We have Alex Dictionary. 135 00:11:01,860 --> 00:11:07,710 And the way that we can add additional cell here at the end is the following. 136 00:11:07,950 --> 00:11:13,920 We just mentioned the dictionary right after in square brackets, we put the Newquay that we want to 137 00:11:13,920 --> 00:11:18,600 insert and then we do equals and mention the value. 138 00:11:19,580 --> 00:11:20,050 All right. 139 00:11:20,430 --> 00:11:29,790 So in our in our case, we'll just do this, Alex, then square brackets and then I have I want to add 140 00:11:29,790 --> 00:11:33,450 an apartment number five to the list, to the dictionary. 141 00:11:33,690 --> 00:11:36,900 So I apply here the key apartment number. 142 00:11:37,050 --> 00:11:40,370 And here I supply the value. 143 00:11:40,530 --> 00:11:47,250 And then after we print the dictionary, we will have this part, which is the old part which was existing 144 00:11:47,250 --> 00:11:47,700 before. 145 00:11:47,880 --> 00:11:53,980 And we will also additionally have the new part, which is the key that we answered and the value easy. 146 00:11:54,000 --> 00:11:54,280 Right. 147 00:11:54,930 --> 00:11:57,120 There's nothing too complicated here. 148 00:11:57,120 --> 00:12:03,900 Once you get the things, once you get down to the core of it, nothing is too complicated. 149 00:12:05,130 --> 00:12:12,210 And finally, last but not least, how can we remove all elements out of the dictionary? 150 00:12:12,210 --> 00:12:20,530 Meaning we want to remove everything to do a clear cache, to do a scratch everything out of the dictionary. 151 00:12:20,550 --> 00:12:22,530 So this one is very simple. 152 00:12:23,160 --> 00:12:29,400 We just use the clear action key and then once we use the clear, we try to print the dictionary and 153 00:12:29,400 --> 00:12:30,120 we get nothing. 154 00:12:30,120 --> 00:12:34,670 We just get clean, curly brackets and that's it. 155 00:12:34,680 --> 00:12:35,550 There's nothing there. 156 00:12:36,330 --> 00:12:36,920 All right. 157 00:12:36,930 --> 00:12:40,440 So this was the advanced part of dictionary. 158 00:12:40,450 --> 00:12:41,790 I hoped you liked it. 159 00:12:41,970 --> 00:12:47,670 We learned a lot of things here, and obviously this is the main part of it. 160 00:12:47,970 --> 00:12:51,390 And try to reverse this lecture. 161 00:12:51,390 --> 00:12:55,920 If you didn't get all the parts, it's sometimes good to hear the same mixture several times. 162 00:12:56,190 --> 00:12:59,850 And this is about it for that part. 163 00:13:01,000 --> 00:13:01,460 All right. 164 00:13:01,470 --> 00:13:10,530 So in the following video, you will get practice regarding this material and afterwards also a resolution 165 00:13:10,530 --> 00:13:11,010 for it. 166 00:13:11,610 --> 00:13:13,660 OK, then that's about it. 167 00:13:13,900 --> 00:13:14,510 Bye bye. 168 00:13:14,520 --> 00:13:15,810 See you in the next lecture.