1 00:00:00,650 --> 00:00:01,160 Welcome back. 2 00:00:01,940 --> 00:00:08,090 I mentioned to you that a dictionaries of values can hold any sort of data type. 3 00:00:08,240 --> 00:00:10,220 But what about the keys. 4 00:00:10,310 --> 00:00:19,490 Up until now I've only used strings to denote a key but could I do something like this could I do one 5 00:00:19,490 --> 00:00:22,970 two three like this. 6 00:00:22,970 --> 00:00:23,930 Well let's have a look. 7 00:00:23,930 --> 00:00:24,760 Let's give it a try. 8 00:00:25,950 --> 00:00:34,110 If I do one two three and I click Run I get one two three. 9 00:00:34,800 --> 00:00:35,160 Awesome. 10 00:00:35,160 --> 00:00:36,530 That works. 11 00:00:37,020 --> 00:00:40,650 What about what about true. 12 00:00:40,770 --> 00:00:48,050 If I select if I have a key true and I click Run will that work yeah. 13 00:00:48,230 --> 00:00:49,480 It looks like it works. 14 00:00:49,490 --> 00:00:50,840 What about a list. 15 00:00:50,840 --> 00:00:54,390 What if I have a list of let's say just a hundred. 16 00:00:54,440 --> 00:00:59,290 Would that work if I click Run Nope. 17 00:00:59,650 --> 00:01:01,160 It doesn't work. 18 00:01:01,180 --> 00:01:04,250 It says on hash table type list. 19 00:01:04,390 --> 00:01:05,660 What does that mean. 20 00:01:06,280 --> 00:01:15,190 Dictionary keys need to have a special property a key needs to be immutable. 21 00:01:15,250 --> 00:01:21,380 That is a key cannot change and numbers billions. 22 00:01:21,400 --> 00:01:26,460 I mean this is a value that cannot change a string. 23 00:01:26,980 --> 00:01:33,700 If you remember is a value that cannot change it's immutable but a list. 24 00:01:33,700 --> 00:01:37,780 If you remember can be changed right on a list. 25 00:01:37,780 --> 00:01:43,120 I can reassign let's say the index of zero to something else. 26 00:01:43,300 --> 00:01:44,390 Right. 27 00:01:44,440 --> 00:01:51,010 So because of that a dictionary says Hey my keys because I'm storing them in memory and I don't want 28 00:01:51,010 --> 00:01:51,820 to lose them. 29 00:01:51,820 --> 00:01:54,770 It has to be something that isn't going to change on me. 30 00:01:54,790 --> 00:02:02,660 Maybe a programmer comes in and by mistake changes this array of 100 to have an index of something else. 31 00:02:02,680 --> 00:02:08,100 Well dictionary doesn't really want that because it doesn't want to lose this value. 32 00:02:08,170 --> 00:02:12,910 So a dictionary key always has to be immutable. 33 00:02:13,080 --> 00:02:19,860 And as we learn a few other things like a couple that we'll see in upcoming videos you can use those 34 00:02:19,860 --> 00:02:21,450 as keys as well. 35 00:02:21,450 --> 00:02:30,270 However most of the time ninety five ninety nine percent of the time a key for a dictionary is usually 36 00:02:30,270 --> 00:02:33,780 something descriptive like a string okay. 37 00:02:33,810 --> 00:02:36,880 But what about this. 38 00:02:37,020 --> 00:02:41,270 What if we have a nother string. 39 00:02:41,310 --> 00:02:43,880 One two three. 40 00:02:44,160 --> 00:02:52,980 And let's just remove this for now what happens when I search for one two three the string. 41 00:02:53,160 --> 00:02:55,810 If I click Run I get. 42 00:02:55,810 --> 00:03:06,500 Hello a key in a dictionary has to be unique because there can only be one key because that key is going 43 00:03:06,500 --> 00:03:10,170 to represent a bookshelf in that memory space. 44 00:03:10,240 --> 00:03:16,680 So anytime I do the same key and maybe add a value it's going to overwrite. 45 00:03:16,690 --> 00:03:19,050 So this no longer exists. 46 00:03:19,090 --> 00:03:25,040 A key has to be unique and it's something that can only exist. 47 00:03:25,180 --> 00:03:26,320 Well just once. 48 00:03:26,350 --> 00:03:29,890 Otherwise we overwrite it which is why you see hello here. 49 00:03:29,920 --> 00:03:31,550 We've lost the array. 50 00:03:31,580 --> 00:03:36,870 One two three let's explore this idea a little bit more in the next video.