1 00:00:12,620 --> 00:00:14,300 Hi, everybody, and welcome. 2 00:00:14,510 --> 00:00:22,460 So now I see completed variables lists and completed the first part of dictionary basics, we'll see 3 00:00:22,460 --> 00:00:29,510 much more examples regarding dictionaries by chance and things are going to be a little bit more complicated. 4 00:00:29,690 --> 00:00:33,920 But as long as you listen to my instructions, everything is going to be just fine. 5 00:00:34,130 --> 00:00:34,880 All right, then. 6 00:00:34,880 --> 00:00:35,540 Let's begin. 7 00:00:37,430 --> 00:00:42,890 So, first of all, let's create a new file in our project and call it. 8 00:00:44,720 --> 00:00:54,340 Collection's dictionary basics and let's leave a nice comment for the future for ourselves. 9 00:00:58,600 --> 00:01:07,000 Yep, so first of all, I want to just mention that this video would be a freestyle video that I will 10 00:01:07,000 --> 00:01:07,630 show you cool. 11 00:01:07,630 --> 00:01:11,820 Still cool stuff and cool tricks that you can use and dictionaries. 12 00:01:11,830 --> 00:01:18,460 And part of this video, the first part will be based on the previous lecture and we'll just going to 13 00:01:18,460 --> 00:01:19,870 see it inside our coat. 14 00:01:20,290 --> 00:01:29,110 So first of all, let's create a new dictionary and not create the. 15 00:01:29,650 --> 00:01:30,630 But create. 16 00:01:30,760 --> 00:01:31,380 Yeah. 17 00:01:32,080 --> 00:01:37,720 And let's give it a name dictionary example. 18 00:01:38,600 --> 00:01:45,790 Um, or let's give it more indicative name like employee. 19 00:01:46,730 --> 00:01:48,120 A new employee. 20 00:01:48,130 --> 00:01:48,490 Yeah. 21 00:01:50,380 --> 00:01:51,880 New employee like that. 22 00:01:52,090 --> 00:01:55,090 And let's start putting values inside. 23 00:01:55,460 --> 00:01:56,810 Let's give the first. 24 00:01:56,810 --> 00:02:03,610 So the key uh first name and our employee is David. 25 00:02:05,740 --> 00:02:09,100 David has a salary of. 26 00:02:11,540 --> 00:02:20,660 Ten thousand dollars, and he works in a small company that some of you might know called Google. 27 00:02:21,380 --> 00:02:22,070 All right. 28 00:02:22,910 --> 00:02:25,760 So first of all, let us just do a simple thing. 29 00:02:25,760 --> 00:02:32,450 Let's just print the dictionary and see that we're OK. 30 00:02:36,310 --> 00:02:38,800 Plus, casting and new employee. 31 00:02:40,200 --> 00:02:42,390 Yeah, so it's runit. 32 00:02:44,340 --> 00:02:45,780 See that everything's fine. 33 00:02:45,950 --> 00:02:50,340 Yeah, so we have the dictionary right here great, so we can continue. 34 00:02:50,810 --> 00:02:59,930 So as you recall in previous videos, in previous video, we found out that we can extract cells with 35 00:02:59,930 --> 00:03:02,200 two ways, so let's try to use it. 36 00:03:02,540 --> 00:03:04,310 So get cell. 37 00:03:05,350 --> 00:03:06,250 Value. 38 00:03:08,450 --> 00:03:15,740 First, we saw the first way was mentioned the dictionary, which is new employee, and then use square 39 00:03:15,740 --> 00:03:18,660 brackets and let's extract the first name. 40 00:03:19,220 --> 00:03:21,730 All right, so you put the key that you want. 41 00:03:21,740 --> 00:03:23,720 It's value being extracted. 42 00:03:23,960 --> 00:03:28,610 So we are putting this key and we want to extract the name. 43 00:03:28,910 --> 00:03:34,460 So it's surrounded with a print action and the comment. 44 00:03:43,540 --> 00:03:49,670 Yeah, get the value of first name key and let's put casting here. 45 00:03:50,830 --> 00:03:51,280 Yeah. 46 00:03:54,520 --> 00:03:57,160 And let's hope, hope for the best. 47 00:03:58,290 --> 00:03:58,680 Whoo! 48 00:03:58,780 --> 00:04:07,330 Yeah, so we got the name David and we have extracted the value of first name, so we have also a second 49 00:04:07,330 --> 00:04:07,780 way. 50 00:04:08,050 --> 00:04:10,000 So get cell value. 51 00:04:12,250 --> 00:04:15,700 Second way, anybody remember how do we do it? 52 00:04:16,180 --> 00:04:22,900 I recommend you to check the attached file to the previous video, the PDF attachment file. 53 00:04:24,160 --> 00:04:26,440 All right, so how do we do it? 54 00:04:26,800 --> 00:04:35,620 We we call out the dictionary and then we put that get by the way, notice that we have many options 55 00:04:35,620 --> 00:04:38,350 here and we will get back to them in a moment. 56 00:04:38,800 --> 00:04:46,400 So new employee then get and then here we want to extract salary, just a different one. 57 00:04:47,320 --> 00:04:55,630 Let's do a print and then get value off salary key. 58 00:04:56,530 --> 00:05:04,360 Yeah, so we want to extract the salary and we'll put here casting of string. 59 00:05:04,830 --> 00:05:06,490 OK, so let's print it. 60 00:05:06,490 --> 00:05:09,940 We're expecting the value ten thousand to be printed out. 61 00:05:11,150 --> 00:05:12,570 OK, so there we see it. 62 00:05:12,580 --> 00:05:13,060 Great. 63 00:05:13,490 --> 00:05:19,540 So now we have basically two actions that we can use to extract values out of the cell. 64 00:05:19,750 --> 00:05:25,900 And the next thing that I want to do before before heading to the next to the next bar, I just want 65 00:05:25,900 --> 00:05:26,980 to mention a small thing. 66 00:05:27,370 --> 00:05:32,230 A pie chart is all is not all is not just a development environment. 67 00:05:32,230 --> 00:05:35,860 It's also a learning tool if you know how to use it. 68 00:05:36,100 --> 00:05:42,850 OK, so Pyfrom can give you hints of what options can you use in your code and then really recommend 69 00:05:42,850 --> 00:05:43,600 you to do it. 70 00:05:44,020 --> 00:05:46,930 And the only way to do it is by experimenting. 71 00:05:47,200 --> 00:05:54,700 I personally studied a lot using by Charm's hints and we will see how to do it right now. 72 00:05:55,090 --> 00:05:58,450 So first of all, let's call out the dictionary. 73 00:05:58,660 --> 00:06:05,460 And just a few moments ago, when we did not get we seen here a pop up with lots of options. 74 00:06:05,650 --> 00:06:10,390 So all of these options are very valuable to use upon dictionaries. 75 00:06:10,570 --> 00:06:12,010 So why not using them? 76 00:06:12,040 --> 00:06:13,340 So let's try to use them. 77 00:06:14,140 --> 00:06:19,600 So first of all, we're already familiar with this guy with Pop. 78 00:06:19,810 --> 00:06:27,490 We apply it on lists in previous lectures and we in previous lectures when we use lists, we mentioned 79 00:06:27,790 --> 00:06:29,710 we mentioned here the index number. 80 00:06:29,950 --> 00:06:38,260 But as you recall in the previous video I mentioned that dictionary is an unordered a collection. 81 00:06:38,380 --> 00:06:41,870 So we can't apply index Salleh index here. 82 00:06:41,980 --> 00:06:42,940 This would be wrong. 83 00:06:43,210 --> 00:06:52,840 So what we want to do is to mention the key here and just going to do an experiment and put Sellery 84 00:06:52,840 --> 00:06:53,230 here. 85 00:06:56,300 --> 00:07:03,410 By the way, it doesn't matter if you put Equitation double quotation marks or just a single one like 86 00:07:03,410 --> 00:07:10,760 this, it's the same effect just as long as you don't do one of each kind like this, OK, as long of 87 00:07:10,940 --> 00:07:14,590 as long as both of them from the same kind, double or single. 88 00:07:14,870 --> 00:07:16,470 This is OK to pie chart. 89 00:07:16,910 --> 00:07:25,280 So let's put celery here and then let's try to print the new employee dictionary. 90 00:07:25,480 --> 00:07:32,720 And what I'm expecting to see is when once we're using Pop that we would like to the cell to be removed 91 00:07:32,930 --> 00:07:35,980 and we're expecting for all this to be removed. 92 00:07:36,020 --> 00:07:37,520 The key and the value. 93 00:07:38,480 --> 00:07:41,570 OK, so let's try to print it and see what happens. 94 00:07:42,380 --> 00:07:42,850 Yes. 95 00:07:42,860 --> 00:07:49,040 So as expected, the salary cell was completely deleted out of the list. 96 00:07:49,040 --> 00:07:50,220 Out of the dictionary. 97 00:07:50,450 --> 00:07:51,710 It's not here anymore. 98 00:07:52,160 --> 00:07:55,760 OK, so I just had the comments removed. 99 00:07:55,760 --> 00:07:59,450 Dictionary cell by using pop. 100 00:08:00,640 --> 00:08:03,520 And I'm just going to copy this one. 101 00:08:04,820 --> 00:08:05,690 And. 102 00:08:06,900 --> 00:08:10,230 Police youth here inside quotation marks. 103 00:08:15,870 --> 00:08:16,560 Yes. 104 00:08:18,890 --> 00:08:29,090 So this is it, this is what we have learned now that if we use dot pop, we can remove the cell from 105 00:08:29,090 --> 00:08:29,810 the dictionary. 106 00:08:30,020 --> 00:08:37,100 So it only by experimenting because I see the dictionary dot and I saw in the pop up lots of options 107 00:08:37,100 --> 00:08:37,550 over there. 108 00:08:37,700 --> 00:08:39,620 And why not using them? 109 00:08:39,650 --> 00:08:41,090 Why not trying to use them? 110 00:08:41,090 --> 00:08:46,160 And we can study lots of things by using and try and experimenting new things and I. 111 00:08:46,160 --> 00:08:46,500 Right. 112 00:08:46,700 --> 00:08:54,320 So it's a good it's highly recommended by me to do experiments and it can be very useful to study new 113 00:08:54,320 --> 00:08:55,060 things like that. 114 00:08:55,520 --> 00:08:58,040 So let's try to do a different thing. 115 00:08:58,220 --> 00:09:00,260 Let's call out the dictionary. 116 00:09:02,900 --> 00:09:10,060 And why do you think if I use the value or Keyes action, what will happen like that? 117 00:09:10,430 --> 00:09:12,800 So can I maybe guess what will happen? 118 00:09:13,490 --> 00:09:19,430 So is it logical to say that if I printed it would give me all of the keys of the dictionary? 119 00:09:19,610 --> 00:09:20,330 Am I right? 120 00:09:20,580 --> 00:09:21,630 That's very logical. 121 00:09:22,010 --> 00:09:29,690 So let's try to print it and see what happens first and then we'll put a comment afterwards. 122 00:09:30,230 --> 00:09:32,400 So it's printed. 123 00:09:32,660 --> 00:09:37,300 So indeed, as we just said, we will see all the keys printed out. 124 00:09:37,850 --> 00:09:43,680 OK, so print out all keys of the dictionary. 125 00:09:44,420 --> 00:09:49,850 So this is also a very powerful tool that we can extract all of the keys at once. 126 00:09:59,270 --> 00:10:02,510 Yes, so casting. 127 00:10:04,450 --> 00:10:12,820 Yeah, so that's great, and I'm just going to copy this one, because we have keys and we also have 128 00:10:13,060 --> 00:10:20,560 values, and it's really logical to understand that both of them doing the extraction in the same way, 129 00:10:20,560 --> 00:10:22,450 one on keys and one on values. 130 00:10:22,660 --> 00:10:29,170 So I'm just going to change the word values in all relevant places and try to print it. 131 00:10:31,850 --> 00:10:41,840 Yeah, and here we want to place values as such and try to print it, and also here we have printed 132 00:10:41,840 --> 00:10:46,140 out we have extracted all values out of the dictionary. 133 00:10:46,700 --> 00:10:47,180 All right. 134 00:10:47,190 --> 00:10:51,800 So this was very, very useful to just experiment. 135 00:10:51,890 --> 00:10:53,100 Just experiment. 136 00:10:53,120 --> 00:10:55,330 Do not be afraid to get some errors. 137 00:10:55,580 --> 00:11:00,560 The worst case scenario is you get an error and the best case scenario that you learn new things. 138 00:11:00,740 --> 00:11:03,410 And once you learn a new thing, you can use it forever. 139 00:11:03,530 --> 00:11:09,230 It gets gets in, your DNA gets in your mind, and then it's yours forever and you can use it for the 140 00:11:09,230 --> 00:11:13,130 wrong according to your requirements. 141 00:11:13,730 --> 00:11:19,970 So now, guys, I'm going to head over to the last part of the theory example part. 142 00:11:20,180 --> 00:11:23,900 And I'm just going to combine two topics together. 143 00:11:24,290 --> 00:11:29,030 As you recall, in our first lessons, we have studied what our variables. 144 00:11:29,270 --> 00:11:32,720 So I'm going to use variables and dictionaries together. 145 00:11:33,170 --> 00:11:39,860 And basically what I'm going to do is instead of hard coding the values and the keys inside the dictionary, 146 00:11:39,860 --> 00:11:46,510 I'm going to create a variable and place a variable instead, a hard coded value as such. 147 00:11:46,520 --> 00:11:53,280 Just put the variable inside and then I'll try to print it and see the value of the dictionary prints, 148 00:11:53,330 --> 00:11:55,480 the variable that I've put inside. 149 00:11:55,850 --> 00:11:59,150 So I'm just going to use a variable. 150 00:12:02,170 --> 00:12:05,800 And place it inside the dictionary. 151 00:12:08,090 --> 00:12:10,230 A dictionary cell. 152 00:12:10,580 --> 00:12:17,000 OK, so my variable will be job title and output developer here. 153 00:12:18,280 --> 00:12:21,640 And and I'm going to create a new. 154 00:12:23,330 --> 00:12:24,200 Dictionary. 155 00:12:26,720 --> 00:12:28,250 And port. 156 00:12:29,290 --> 00:12:31,150 Like job. 157 00:12:32,950 --> 00:12:33,700 Title. 158 00:12:35,330 --> 00:12:43,490 Yeah, and put job title, you know what, let's give it a different name, job title valued small, 159 00:12:43,490 --> 00:12:45,160 correct, more indicative. 160 00:12:45,410 --> 00:12:48,830 So that's just copy it and place it here. 161 00:12:50,830 --> 00:12:57,100 OK, and now let's just print it, print the new. 162 00:12:58,430 --> 00:13:03,410 Dictionary plus casting and new dictionary. 163 00:13:04,350 --> 00:13:12,770 All right, so what I'm expecting to get is to print out the list, but as you can recall, as you can 164 00:13:12,770 --> 00:13:16,070 see, I'm not using a hard coded values here. 165 00:13:16,640 --> 00:13:20,810 I'm just using a variable and placing it inside a dictionary. 166 00:13:21,200 --> 00:13:22,260 So it's printed. 167 00:13:23,240 --> 00:13:24,390 There you have it. 168 00:13:24,410 --> 00:13:25,520 We don't see anything. 169 00:13:26,030 --> 00:13:26,870 All right. 170 00:13:26,870 --> 00:13:29,570 So let's see what's wrong. 171 00:13:29,930 --> 00:13:34,490 Oh, obviously, we printed the old dictionary. 172 00:13:35,370 --> 00:13:37,100 New dictionary. 173 00:13:38,380 --> 00:13:48,130 Yep, so this work, yep, so we can see the new dictionary printed out and you can see how topics are 174 00:13:48,130 --> 00:13:49,370 gathering together. 175 00:13:49,540 --> 00:13:54,160 So now you can also use dictionaries together with variables. 176 00:13:54,280 --> 00:13:59,920 And all the same, you can also apply variables inside lists as well. 177 00:14:00,220 --> 00:14:07,600 So, like both topics are mixed, and as long as we go forward, they're all topics will be combined 178 00:14:07,600 --> 00:14:13,480 together and we can invent and we can create cool stuff using all the tools together. 179 00:14:13,810 --> 00:14:19,700 So this will be the final part of the theory basics regarding dictionaries. 180 00:14:19,720 --> 00:14:26,320 I will see you in the next video and we will practice at the dictionaries and that's about it. 181 00:14:26,650 --> 00:14:27,120 All right. 182 00:14:27,340 --> 00:14:27,850 Bye bye.