1 00:00:11,860 --> 00:00:13,930 Hi, everyone, and welcome. 2 00:00:14,590 --> 00:00:23,310 OK, so let's try to resolve Dictionary's practice assignments and let me just open by charm. 3 00:00:23,440 --> 00:00:24,160 All right. 4 00:00:24,730 --> 00:00:27,860 So once I'm open, let's create a new file. 5 00:00:28,690 --> 00:00:29,440 Call it. 6 00:00:31,160 --> 00:00:40,310 Collection's dictionary practice basics and here is well. 7 00:00:49,310 --> 00:00:51,150 Yeah, so are we good to go? 8 00:00:51,440 --> 00:00:57,800 So, first of all, let's create a dictionary about Alex. 9 00:00:59,550 --> 00:01:09,420 So the dictionary goes as following square brackets and then we have age, Alix's is 32 years old. 10 00:01:10,510 --> 00:01:11,200 And. 11 00:01:12,310 --> 00:01:13,090 Married. 12 00:01:14,960 --> 00:01:22,580 Yes, by the way, we can also put boolean variable here as following, but the assignments said to 13 00:01:22,580 --> 00:01:31,220 say to set a string of yes and last one is kids, which is which has the value of three. 14 00:01:32,190 --> 00:01:37,360 OK, so this was the first thing you needed to do. 15 00:01:37,760 --> 00:01:39,140 Let's print it out. 16 00:01:40,360 --> 00:01:43,010 This is Simon Nimo, number one. 17 00:01:43,540 --> 00:01:45,730 This is Alix's. 18 00:01:47,200 --> 00:01:48,010 Dictionary. 19 00:01:49,780 --> 00:01:58,690 And plus casting and Alex, yep, so it's printed out, see that we're fine, all right. 20 00:01:58,760 --> 00:02:01,530 And so we have printed out the dictionary successfully. 21 00:02:02,380 --> 00:02:02,800 Great. 22 00:02:02,800 --> 00:02:05,860 So let's head over to the next assignment. 23 00:02:06,130 --> 00:02:09,910 And the assignment said that you need to extract. 24 00:02:10,910 --> 00:02:13,190 Values of the dictionary. 25 00:02:16,530 --> 00:02:18,040 Into variables. 26 00:02:18,120 --> 00:02:18,680 Correct. 27 00:02:22,060 --> 00:02:25,420 So let's create reprints, yeah. 28 00:02:26,270 --> 00:02:37,100 It's great, three prints, copy it and then paste and paste and inside those prints, let's state that 29 00:02:37,100 --> 00:02:43,010 we are in assignment number two and we're going to print off page value. 30 00:02:43,020 --> 00:02:43,500 Correct. 31 00:02:44,000 --> 00:02:46,340 So looking at the dictionary. 32 00:02:46,640 --> 00:02:47,070 All right. 33 00:02:47,070 --> 00:02:49,360 So we have three cells here. 34 00:02:49,730 --> 00:02:53,210 This is the first one second and third. 35 00:02:53,420 --> 00:02:58,520 And again, I'm mentioning mentioning that you do not have indexes for those cells. 36 00:02:58,520 --> 00:03:04,570 I'm just counting them for myself and for you guys to understand that we are discussing the same thing. 37 00:03:05,090 --> 00:03:09,240 So we want to print the value, uh, print the value of age. 38 00:03:09,290 --> 00:03:09,820 All right. 39 00:03:10,250 --> 00:03:20,300 And what you were asked to do in this assignment before the prints is to create three variables and 40 00:03:20,300 --> 00:03:24,890 put the values of the dictionary inside those variables. 41 00:03:25,250 --> 00:03:26,690 So we have the H. 42 00:03:26,840 --> 00:03:27,280 Yeah. 43 00:03:27,560 --> 00:03:29,440 And how do we extract a value? 44 00:03:29,480 --> 00:03:36,400 We just mentioned the dictionary, then square brackets and then put the key inside. 45 00:03:36,740 --> 00:03:37,150 Yeah. 46 00:03:37,610 --> 00:03:40,070 So again, we're doing the. 47 00:03:42,070 --> 00:03:43,180 Marriage status. 48 00:03:47,150 --> 00:03:50,570 And then we put the dictionary square brackets. 49 00:03:52,170 --> 00:03:54,030 And put the key inside. 50 00:03:55,910 --> 00:03:57,270 Then we have kids. 51 00:03:58,320 --> 00:04:01,260 Or to be more exact number of kids. 52 00:04:02,380 --> 00:04:10,060 Alex and kids, yeah, so this is what we have learned in the previous video, that this is how you 53 00:04:10,330 --> 00:04:19,420 can assign variables into, uh, like to sign to vet to a variable a, uh, value of a dictionary. 54 00:04:19,790 --> 00:04:23,500 And then what we need to do is print the age of the value. 55 00:04:24,620 --> 00:04:26,240 Print of age value. 56 00:04:26,280 --> 00:04:32,670 Yeah, so we do casting and we put Asian side, Asian side. 57 00:04:33,140 --> 00:04:33,590 All right. 58 00:04:33,590 --> 00:04:38,080 So let's do a quick example for the first one that we will know that we're in the right way. 59 00:04:41,120 --> 00:04:45,950 Right, so we have extracted successfully the aged value. 60 00:04:47,060 --> 00:04:54,200 All right, so first of all, we created a new new variable, which is age, and then we put an equals 61 00:04:54,200 --> 00:04:58,850 mark that this value we want to put inside the age variable. 62 00:04:59,060 --> 00:05:00,680 And what do we have here? 63 00:05:00,710 --> 00:05:07,160 Here we have the dictionary mentioning square brackets, and then inside we put the key and these key 64 00:05:07,730 --> 00:05:12,170 belong value will be extracted by this action. 65 00:05:12,440 --> 00:05:17,930 So basically, it's the same thing as stating H equals 32. 66 00:05:18,020 --> 00:05:18,410 All right. 67 00:05:18,440 --> 00:05:20,630 So this one's output is 32. 68 00:05:20,900 --> 00:05:24,380 It extracts the value of the key that we mentioned. 69 00:05:24,710 --> 00:05:25,070 All right. 70 00:05:26,870 --> 00:05:27,540 Oh, sorry. 71 00:05:28,790 --> 00:05:31,040 All right, so then we have. 72 00:05:33,030 --> 00:05:38,580 We also need to do the print off of the other variables or print off. 73 00:05:40,580 --> 00:05:41,780 Marriage status. 74 00:05:43,670 --> 00:05:45,260 Value, yeah. 75 00:05:47,010 --> 00:05:50,710 SDR, by the way, anybody knows. 76 00:05:50,850 --> 00:05:52,760 Do we need casting here or not? 77 00:05:54,580 --> 00:06:02,680 And I'm asking this because let's have a quick look at the value of the married keys is a string. 78 00:06:02,680 --> 00:06:05,470 So do we need to put casting here? 79 00:06:06,570 --> 00:06:07,740 So let's find out. 80 00:06:07,770 --> 00:06:10,980 Yeah, and in the last one. 81 00:06:12,120 --> 00:06:13,650 We have to, yeah. 82 00:06:19,640 --> 00:06:20,480 Print off. 83 00:06:21,710 --> 00:06:22,440 No. 84 00:06:22,630 --> 00:06:29,840 Yeah, we like this number of kids, yeah, so value. 85 00:06:31,950 --> 00:06:34,530 And then we pulled the string. 86 00:06:34,560 --> 00:06:42,660 This is indeed a, uh, string uh, yeah, sorry, it's an integer. 87 00:06:43,180 --> 00:06:44,400 So this is an integer. 88 00:06:44,400 --> 00:06:47,270 So we definitely need casting because we have a string here. 89 00:06:47,550 --> 00:06:51,780 And if we don't do casting, we have two types of string and is let's print it. 90 00:06:51,780 --> 00:06:56,850 And the question mark, I just want to remind you, want to see what happens here as we didn't do casting. 91 00:07:04,200 --> 00:07:11,620 Yes, so everything worked just fine, and as we just discussed, you do not have to put casting on 92 00:07:11,620 --> 00:07:17,660 marital status, and the reason is because when we pull out the value of this key, which is the value. 93 00:07:17,670 --> 00:07:18,180 Yes. 94 00:07:18,490 --> 00:07:20,340 So it is already a string. 95 00:07:20,340 --> 00:07:25,690 So we don't need to, uh, we don't need to cast a string into a string. 96 00:07:25,710 --> 00:07:27,870 This is this is not logical. 97 00:07:27,880 --> 00:07:30,240 So we don't need to put the casting here. 98 00:07:31,670 --> 00:07:36,230 Yep, so this was the second assignment and the third assignment was. 99 00:07:38,000 --> 00:07:44,240 Bonus one, yeah, and find a way to change. 100 00:07:45,440 --> 00:07:47,150 Dictionary value. 101 00:07:48,830 --> 00:07:57,020 Online, yeah, so we had like a phrase that I asked you to to search by. 102 00:07:58,580 --> 00:08:03,990 So the phrase was Python update value of dictionary. 103 00:08:04,460 --> 00:08:08,030 So just randomly, I'm going to not randomly and just going to speak. 104 00:08:08,030 --> 00:08:14,030 Always the first results here, as long as they're not promoted. 105 00:08:14,090 --> 00:08:14,540 All right. 106 00:08:14,550 --> 00:08:17,540 So let's go to programs, by the way. 107 00:08:17,540 --> 00:08:25,130 I just want to say that all information that we take from that program is dot com is rights reserved 108 00:08:25,130 --> 00:08:26,720 to program is all right. 109 00:08:27,170 --> 00:08:31,020 And now we will see here from the top. 110 00:08:31,040 --> 00:08:35,360 We already discussed it in the previous video that we just need to mention. 111 00:08:35,840 --> 00:08:39,760 The dictionary then used the DOT update action key. 112 00:08:39,980 --> 00:08:49,070 And here, inside, here, inside, you see in the square brackets the phrase other and we not you can't 113 00:08:49,070 --> 00:08:51,720 quite sure understand what is on the other. 114 00:08:52,010 --> 00:08:54,590 So let's go a bit down to see an example. 115 00:08:54,590 --> 00:09:01,370 And isn't the as we saw in the previous video, so we have seen that we have a dictionary, one which 116 00:09:01,370 --> 00:09:06,860 is the best one, and we have the D D one, which is the helper dictionary. 117 00:09:07,250 --> 00:09:11,270 And here we have only one key and one value. 118 00:09:11,450 --> 00:09:17,690 So the key here is to correct and the key here is to as well. 119 00:09:18,260 --> 00:09:27,200 So once we we call out the base dictionary D and we hit the update Key Action Action Key. 120 00:09:27,590 --> 00:09:35,030 Once we put inside the helper dictionary, which is the one, it will take this key and we'll take this 121 00:09:35,040 --> 00:09:41,580 value and it will search where in the base dictionary we have the same key. 122 00:09:41,900 --> 00:09:44,170 OK, so we have here the same key. 123 00:09:44,180 --> 00:09:51,020 So it will replace the value of the helper instead of what we have in the base dictionary. 124 00:09:51,260 --> 00:09:52,820 So this is what we're going to do now. 125 00:09:52,850 --> 00:09:53,330 OK. 126 00:09:54,920 --> 00:10:04,040 So we have assignment number four, which was the following change. 127 00:10:05,300 --> 00:10:06,200 Of age. 128 00:10:07,250 --> 00:10:07,730 Kee. 129 00:10:09,460 --> 00:10:18,010 Change of value, let's say, sell value from 32 to 33, correct? 130 00:10:18,550 --> 00:10:23,020 So what we're going to do now is, first of all, to create an age. 131 00:10:24,120 --> 00:10:24,900 Helper. 132 00:10:26,040 --> 00:10:33,180 Dictionary and we will stay there, the same key that we have in the original dictionary, which is 133 00:10:33,180 --> 00:10:43,920 age, and we will put the the the goal value, which is 33 and right after we will mention the base 134 00:10:44,280 --> 00:10:54,140 dictionary, then dot the action key and inside we will just insert the helper dictionary as following. 135 00:10:54,510 --> 00:11:04,290 So what's going to happen now is once we will apply the update of, uh, upon the dictionary with the 136 00:11:04,290 --> 00:11:06,130 help of the helper dictionary. 137 00:11:06,600 --> 00:11:13,920 So the code will take this key, go to the go to the base dictionary, which is this will find the same 138 00:11:13,920 --> 00:11:18,900 key here and it will replace this value with the new one. 139 00:11:19,890 --> 00:11:23,550 So let's try to print and see that we're correct. 140 00:11:32,640 --> 00:11:35,700 All right, so now we're going to print. 141 00:11:37,070 --> 00:11:46,040 The Alex dictionary one more time and we're expecting to see a 33 value inside the sale of H. 142 00:11:49,790 --> 00:11:58,700 Yes, so this actually happened, we have the value 32 and once we use the Help dictionary to replace 143 00:11:58,700 --> 00:12:00,760 the value, it is now 33. 144 00:12:01,400 --> 00:12:01,850 Great. 145 00:12:01,940 --> 00:12:06,740 All right, let's head over to the following one. 146 00:12:07,010 --> 00:12:18,140 So in the following assignment, we were asked to change the number of kids as Alex has a new kid in 147 00:12:18,140 --> 00:12:19,010 the family. 148 00:12:21,520 --> 00:12:29,260 Joining the family may be, yeah, and what are we going to do as all as well? 149 00:12:29,600 --> 00:12:34,140 A creative kid's helper dictionary. 150 00:12:34,780 --> 00:12:42,200 Yeah, put the key kids inside and put the value for which is what we want to put inside the cell. 151 00:12:42,460 --> 00:12:44,290 Right now we have the value three. 152 00:12:44,830 --> 00:12:45,300 Yeah. 153 00:12:46,720 --> 00:12:50,320 So now it's not kids, it's kids. 154 00:12:52,380 --> 00:13:01,290 Yeah, and now we're just going to do the same thing we did before, I like that update and then put 155 00:13:01,290 --> 00:13:03,860 the Kids Helper dictionary inside. 156 00:13:04,350 --> 00:13:07,830 And again, let's just copy this one. 157 00:13:09,390 --> 00:13:18,180 And based here just before running, I want to do a small thing, I just want to mention here a change 158 00:13:18,180 --> 00:13:23,760 of age and here it is, change of. 159 00:13:24,660 --> 00:13:25,500 Kids, no. 160 00:13:26,660 --> 00:13:31,570 Number of kids, yeah, and let's print it and see what happens. 161 00:13:33,700 --> 00:13:34,510 Oh, no. 162 00:13:34,810 --> 00:13:35,490 Oh, no. 163 00:13:35,500 --> 00:13:36,490 Something happened here. 164 00:13:36,940 --> 00:13:37,750 Oh, I see. 165 00:13:37,750 --> 00:13:38,200 I see. 166 00:13:38,200 --> 00:13:40,300 So we have like a Syntex out here. 167 00:13:40,910 --> 00:13:43,680 We need to put this a sign right here. 168 00:13:44,050 --> 00:13:45,240 Let's try to run it. 169 00:13:45,250 --> 00:13:45,610 Yeah. 170 00:13:46,210 --> 00:13:46,620 Yeah. 171 00:13:46,630 --> 00:13:50,680 So the value changed from three to four, as we expected. 172 00:13:50,920 --> 00:13:51,430 Great. 173 00:13:51,910 --> 00:13:52,480 Great guy. 174 00:13:52,520 --> 00:13:54,670 So we're heading in the right way. 175 00:13:54,910 --> 00:13:55,960 Heading in the right way. 176 00:13:56,630 --> 00:14:01,690 Now let's try to do the following thing as we already studied. 177 00:14:01,870 --> 00:14:08,400 And let's just try to print all of the values and keys, uh, of the dictionary. 178 00:14:09,190 --> 00:14:14,890 Yeah, but right here, I just want to maintain order or put the assignment number. 179 00:14:16,620 --> 00:14:25,290 Yeah, so right now we are heading to the sixth one and in the sixth one, we would like to print out 180 00:14:25,830 --> 00:14:26,760 all the keys. 181 00:14:31,210 --> 00:14:35,740 Of Ilex dictionary, and we will do it in the following way. 182 00:14:46,600 --> 00:14:56,880 And we can do it using, first of all, casting and yeah, this is unnecessary and will put Alex here 183 00:14:57,370 --> 00:14:59,680 and then we put that keys. 184 00:15:00,100 --> 00:15:02,260 Yeah, we have seen it in the previous lectures. 185 00:15:02,530 --> 00:15:09,440 And also let's copy this one and why I'll copy. 186 00:15:09,460 --> 00:15:10,050 You know what? 187 00:15:10,060 --> 00:15:16,360 Let's not copy it, because I want you to see maybe you can get some new information while I'm explaining 188 00:15:16,360 --> 00:15:18,230 and showing you the way. 189 00:15:18,820 --> 00:15:19,300 All right. 190 00:15:19,300 --> 00:15:26,020 So the keys and now we need to print out values of Alex Dictionary. 191 00:15:26,410 --> 00:15:35,340 And here we are in assignment number seven, print all values of Ilex Dictionary. 192 00:15:35,350 --> 00:15:36,640 Yeah, it's pretty much the same. 193 00:15:36,640 --> 00:15:36,940 Yeah. 194 00:15:37,420 --> 00:15:39,650 Quite frankly, it's pretty much the same. 195 00:15:40,120 --> 00:15:44,740 So here it's Alex Dot values and printing it out. 196 00:15:45,550 --> 00:15:46,000 Yeah. 197 00:15:46,000 --> 00:15:47,680 Not forgetting the plus here. 198 00:15:48,630 --> 00:15:49,780 Oh OK. 199 00:15:50,080 --> 00:15:52,150 So let's print it. 200 00:15:53,700 --> 00:15:54,360 Yep. 201 00:15:54,570 --> 00:16:01,050 All right, so we have alkies print it out and let's just verify we have age married and kids and we 202 00:16:01,050 --> 00:16:04,210 have old values printed out, which is age 33. 203 00:16:04,500 --> 00:16:05,010 Yes. 204 00:16:05,010 --> 00:16:06,980 And number of kids, which is now four. 205 00:16:07,440 --> 00:16:11,220 And that's about this part. 206 00:16:12,060 --> 00:16:15,950 So I just want to summarize what we have just did in this video. 207 00:16:16,200 --> 00:16:24,920 So we have we have resolved all the practice, basic assignments, and we are now familiar with dictionaries. 208 00:16:24,930 --> 00:16:30,390 We know how to assign and to a certain variable a value of a dictionary. 209 00:16:31,110 --> 00:16:36,890 We know how to change values inside the dictionary using a helper dictionary. 210 00:16:37,260 --> 00:16:42,810 And we also know how to print out the keys and values of a dictionary. 211 00:16:43,110 --> 00:16:46,050 And that's about this topic. 212 00:16:46,410 --> 00:16:54,090 In the next video, we'll start discussing the advanced part of dictionaries there. 213 00:16:54,090 --> 00:17:01,830 You would learn how to do some advanced manipulation on dictionaries as copying a dictionary, deleting 214 00:17:01,830 --> 00:17:06,420 all its values and how how to create a nested dictionary. 215 00:17:06,720 --> 00:17:12,600 And following that, you will also encounter the practice of the advanced part as well. 216 00:17:12,840 --> 00:17:22,860 And this is, quite frankly, a really important topic as dictionaries are used worldwide and in very, 217 00:17:22,860 --> 00:17:25,560 very large scale. 218 00:17:25,620 --> 00:17:29,990 And personally, I also use dictionaries a lot in my automation projects. 219 00:17:30,390 --> 00:17:30,840 So it's a.