1 00:00:00,600 --> 00:00:01,180 Welcome back. 2 00:00:01,830 --> 00:00:09,300 I mentioned to you that a dictionaries of values can hold any sort of data type, but what about the 3 00:00:09,300 --> 00:00:09,780 keys? 4 00:00:10,260 --> 00:00:15,690 Up until now, I've only used strings to denote a key. 5 00:00:16,410 --> 00:00:18,510 But could I do something like this? 6 00:00:18,510 --> 00:00:21,270 Could I do one, two, three like this? 7 00:00:22,890 --> 00:00:28,020 Well, let's have a look, let's give it a try if I do one, two, three. 8 00:00:29,410 --> 00:00:30,310 And I click run. 9 00:00:32,580 --> 00:00:35,700 I get one, two, three, awesome, that works. 10 00:00:36,930 --> 00:00:39,930 What about what about true? 11 00:00:40,680 --> 00:00:45,920 If I select if I have a key true and I click run, will that work? 12 00:00:47,530 --> 00:00:49,180 Yeah, it looks like it works. 13 00:00:49,450 --> 00:00:50,830 What about a list? 14 00:00:50,860 --> 00:00:53,560 What if I have a list of, let's say, just one? 15 00:00:54,370 --> 00:00:55,570 Would that work? 16 00:00:56,470 --> 00:01:05,230 If I click run, nope, it doesn't work, it says uncatchable type list, what does that mean? 17 00:01:06,230 --> 00:01:10,340 Dictionary keys need to have a special property. 18 00:01:11,260 --> 00:01:22,240 A key needs to be immutable, that is a key, cannot change and numbers booleans, I mean, this is 19 00:01:22,240 --> 00:01:24,610 a value that cannot change. 20 00:01:25,390 --> 00:01:31,390 A string, if you remember, is a value that cannot change. 21 00:01:31,390 --> 00:01:35,680 It's immutable, but a list, if you remember, can be changed. 22 00:01:35,680 --> 00:01:42,760 Right on a list I can reassign, let's say, the index of zero to something else. 23 00:01:43,240 --> 00:01:43,610 Right. 24 00:01:44,380 --> 00:01:50,860 So because of that, a dictionary says, hey, my keys, because I'm storing them in memory and I don't 25 00:01:50,860 --> 00:01:51,620 want to lose them. 26 00:01:51,730 --> 00:01:54,700 It has to be something that isn't going to change on me. 27 00:01:54,730 --> 00:02:02,090 Maybe a programmer comes in and by mistake changes this array of 100 to have an index of something else. 28 00:02:02,620 --> 00:02:02,920 Well. 29 00:02:04,200 --> 00:02:07,570 Dictionary doesn't really want that because it doesn't want to lose this value. 30 00:02:08,100 --> 00:02:11,820 So a dictionary key always has to be immutable. 31 00:02:12,980 --> 00:02:19,850 And as we learn a few other things, like a couple that we'll see in upcoming videos, you can use those 32 00:02:19,850 --> 00:02:20,790 as keys as well. 33 00:02:21,410 --> 00:02:30,680 However, most of the time, 95, 99 percent of the time, a key for a dictionary is usually something 34 00:02:30,680 --> 00:02:32,240 descriptive, like a string. 35 00:02:33,500 --> 00:02:40,070 OK, but what about this, what if we have a another string? 36 00:02:41,230 --> 00:02:45,720 One, two, three, and let's just remove this for now. 37 00:02:48,080 --> 00:02:56,210 What happens when I search for one, two, three, the string, if I click run, I get hello. 38 00:02:58,020 --> 00:03:06,720 A key in a dictionary has to be unique because there can only be one key because that key is going to 39 00:03:06,720 --> 00:03:09,740 represent a bookshelf in that memory space. 40 00:03:10,170 --> 00:03:16,530 So any time I do the same key and maybe add a value, it's going to overwrite. 41 00:03:16,620 --> 00:03:18,780 So this no longer exists. 42 00:03:19,020 --> 00:03:26,270 A key has to be unique and it's something that can only exist well, just once. 43 00:03:26,280 --> 00:03:29,720 Otherwise we overwrite it, which is why you see hello here. 44 00:03:29,850 --> 00:03:31,200 We've lost the array. 45 00:03:31,500 --> 00:03:32,790 One, two, three. 46 00:03:34,020 --> 00:03:36,720 Let's explore this idea a little bit more in the next video.