1 00:00:12,840 --> 00:00:21,470 Welcome to this video, so we will head over to part two in collections once we completed the list part, 2 00:00:21,600 --> 00:00:29,190 we would start today starting what our dictionaries and we'll start off the theory part real quick and 3 00:00:29,190 --> 00:00:30,660 held over to the examples. 4 00:00:31,200 --> 00:00:35,390 So dictionaries he's in on all the type of collection python. 5 00:00:36,270 --> 00:00:37,200 What does it mean? 6 00:00:37,200 --> 00:00:46,380 That it's unordered, meaning that once we have a list, for example, we had we had sales. 7 00:00:46,410 --> 00:00:46,860 Right. 8 00:00:47,280 --> 00:00:52,880 We had for example, we had items inside the list like this. 9 00:00:53,790 --> 00:00:54,300 All right. 10 00:00:54,300 --> 00:00:57,470 So we had strings, we had integers and so on. 11 00:00:57,750 --> 00:00:59,880 So for each cell, we had an index. 12 00:00:59,880 --> 00:01:02,490 This was Index Zero and X1 and so on. 13 00:01:02,820 --> 00:01:06,810 But in dictionaries, we do not have index values for ourselves. 14 00:01:07,350 --> 00:01:08,280 We do not have them. 15 00:01:08,290 --> 00:01:11,110 So that's what it means, that it's unordered. 16 00:01:11,580 --> 00:01:18,540 So in other words, we cannot access the information inside the cell by an index, but we can do it 17 00:01:18,540 --> 00:01:19,500 in different ways. 18 00:01:19,500 --> 00:01:20,760 We will see it in a few minutes. 19 00:01:21,540 --> 00:01:28,840 So in dictionary you have items and a dictionary item has a key and value pair. 20 00:01:29,100 --> 00:01:34,870 So the information contained in each cell would have two values, a key and a value. 21 00:01:35,220 --> 00:01:35,730 All right. 22 00:01:35,850 --> 00:01:38,550 Both of them would be in one cell. 23 00:01:38,550 --> 00:01:40,980 So each cell has to contain them both. 24 00:01:42,770 --> 00:01:49,250 Once the key of the dictionary item or dictionary sale, if you like, is the same term, use no one. 25 00:01:49,490 --> 00:01:51,580 We can retrieve the value of it. 26 00:01:51,710 --> 00:01:57,440 So once we know the key, we can retrieve the value that is attached to that key. 27 00:01:58,640 --> 00:02:03,200 In Python, it is expressed as a as a pair key value. 28 00:02:03,590 --> 00:02:03,890 All right. 29 00:02:03,890 --> 00:02:06,970 So, for example, we're talking to our co-worker. 30 00:02:07,280 --> 00:02:12,980 So if we're going to ask him something about this, so are we going to discuss like what's the information 31 00:02:12,980 --> 00:02:13,930 inside the list? 32 00:02:14,300 --> 00:02:19,810 What is the index of the sale that our co-workers is talking about, for example? 33 00:02:20,150 --> 00:02:27,970 But once we discover once we discuss dictionaries, we would ask him, OK, are you talking about the 34 00:02:28,250 --> 00:02:34,210 the key value, like named John or are you talking about the salary 10000? 35 00:02:34,220 --> 00:02:38,180 Like, give me your key and value so I'll know what you are talking about. 36 00:02:39,090 --> 00:02:43,330 OK, so this is like the expression you express it as a pair. 37 00:02:45,280 --> 00:02:52,300 The values in the dictionary can be one of sorry, the values of addiction can be of any types, the 38 00:02:52,300 --> 00:02:55,540 values, but the key must be immutable type. 39 00:02:56,020 --> 00:02:56,770 What does it mean? 40 00:02:56,770 --> 00:03:01,990 Immutable type tasks to be a float integer string or a tuple? 41 00:03:02,440 --> 00:03:06,550 We haven't discussed all yet, but we will in a few videos. 42 00:03:06,550 --> 00:03:12,970 But for now, just remember that the key must be one of those kind and also it must be unique. 43 00:03:13,120 --> 00:03:20,530 So a dictionary cannot have like several cells, like more than one cell with the same key. 44 00:03:20,650 --> 00:03:22,600 It has to have unique keys. 45 00:03:24,150 --> 00:03:30,060 OK, so a dictionary declaration of dictionary is being done like this with curly brackets. 46 00:03:30,420 --> 00:03:38,190 OK, so if you'd like to to declare a dictionary, we do it with curly brackets as opposed to a list 47 00:03:39,000 --> 00:03:42,930 that we did it with square brackets like this. 48 00:03:43,290 --> 00:03:44,910 So that's basically the difference. 49 00:03:44,940 --> 00:03:49,140 So if you see an empty dictionary, you can recognize it by the curly brackets. 50 00:03:50,250 --> 00:03:50,720 All right. 51 00:03:51,360 --> 00:03:52,430 So let's go on. 52 00:03:52,740 --> 00:03:55,920 And if you'd like to insert items into. 53 00:03:56,840 --> 00:04:05,440 Into it will use common between the cells and two dots between the key and the value of each cell, 54 00:04:05,780 --> 00:04:07,160 and what does this mean? 55 00:04:07,460 --> 00:04:14,230 All right, so we have declared the dictionary and now we'd like to put information inside the cells. 56 00:04:14,690 --> 00:04:16,880 So this would be cell number one. 57 00:04:17,150 --> 00:04:18,330 It doesn't have index. 58 00:04:18,350 --> 00:04:18,670 All right. 59 00:04:18,680 --> 00:04:20,900 I'm always focusing on it. 60 00:04:21,390 --> 00:04:23,960 The dictionary does not have index zero. 61 00:04:23,960 --> 00:04:26,180 It does not have it just because. 62 00:04:26,180 --> 00:04:27,530 I want to explain you guys. 63 00:04:27,530 --> 00:04:29,210 What cell am I talking about? 64 00:04:29,210 --> 00:04:31,860 So I'm referring it to the as the first cell. 65 00:04:32,390 --> 00:04:34,640 So this one is the first cell. 66 00:04:34,640 --> 00:04:36,920 It has a key, which is a name. 67 00:04:37,610 --> 00:04:38,120 All right. 68 00:04:38,120 --> 00:04:39,500 The name is a string. 69 00:04:39,500 --> 00:04:42,800 So it's one of the the types that we can use. 70 00:04:43,310 --> 00:04:45,350 And then we have two dots. 71 00:04:47,020 --> 00:04:55,270 And then we have the value, Rachel, so key value there and we have the second sale before it will 72 00:04:55,270 --> 00:04:59,170 put a comma, and then we have here the key, which is a string. 73 00:05:00,870 --> 00:05:05,020 And then we have the value, which is a integer. 74 00:05:05,280 --> 00:05:07,280 OK, so it works like this. 75 00:05:07,860 --> 00:05:09,260 So it's pretty easy. 76 00:05:09,480 --> 00:05:16,620 You see, it's a relative of lists, but it's built off a bit differently because we have a key value, 77 00:05:16,860 --> 00:05:18,660 comma, key value. 78 00:05:19,260 --> 00:05:26,660 And in this we just had on in each cell, we had one information, one value divided with commas. 79 00:05:26,670 --> 00:05:29,040 But here we have a key value in Excel. 80 00:05:30,210 --> 00:05:30,620 All right. 81 00:05:31,080 --> 00:05:36,650 So let's head over to a few simple examples before heading up to the practice part in pie chart. 82 00:05:37,470 --> 00:05:43,320 And the first example will be of how to pull out the value of a cell. 83 00:05:43,590 --> 00:05:44,540 We have two ways. 84 00:05:44,550 --> 00:05:45,080 This is way. 85 00:05:45,090 --> 00:05:47,640 Number one, to pull out cells of value. 86 00:05:47,760 --> 00:05:50,880 We need to mention the key like this. 87 00:05:51,210 --> 00:05:51,540 All right. 88 00:05:51,540 --> 00:06:00,270 So we'll do the print here and then we call out the dictionary and inside square brackets will just 89 00:06:00,270 --> 00:06:02,490 put the key that we want. 90 00:06:02,760 --> 00:06:07,500 Once we print it like this, the output will the output will be the value. 91 00:06:08,370 --> 00:06:15,420 So, again, dictionary and inside the square brackets, we will put the key. 92 00:06:15,900 --> 00:06:19,740 Once we print all this together, we would get the value. 93 00:06:21,180 --> 00:06:26,160 And the second way to extract a value is in the following way. 94 00:06:26,310 --> 00:06:30,060 We can use the dot, get action keyword like this. 95 00:06:30,390 --> 00:06:41,400 So here inside the print, we will call out the dictionary and then use dot get and inside we will mention 96 00:06:41,400 --> 00:06:41,990 the key. 97 00:06:42,480 --> 00:06:43,020 All right. 98 00:06:43,050 --> 00:06:45,900 We will also we will do this again. 99 00:06:45,900 --> 00:06:54,150 We will just call out the dictionary, then dot get and then inside the brackets, the round brackets 100 00:06:54,150 --> 00:06:55,550 will mention the key. 101 00:06:56,340 --> 00:06:58,980 So you can see the difference in the syntax here. 102 00:06:59,280 --> 00:07:05,970 And the first way we call the dictionary and then we have square brackets and we mentioned the key here. 103 00:07:06,960 --> 00:07:13,620 And in the second way, we call out the dictionary, we have the dot get keyword and then we have around 104 00:07:13,710 --> 00:07:21,650 brackets and the key mentions inside and the output will be the value, same as the first one. 105 00:07:21,960 --> 00:07:31,020 So this will complete our basic basic theory regarding dictionaries will hand over to some examples 106 00:07:31,020 --> 00:07:34,610 in polytrauma right away, and that's about Rigi. 107 00:07:34,690 --> 00:07:36,510 So see you in the next video.