1 00:00:00,820 --> 00:00:08,260 By the way, there is actually one more way that we've actually seen in lists how to look for an item 2 00:00:08,470 --> 00:00:09,340 in a dictionary. 3 00:00:10,750 --> 00:00:19,120 Remember how enlists we used the key word when we said something along the lines of, hey, is I in 4 00:00:19,690 --> 00:00:26,170 a list that contains I or we even used a string like, hi? 5 00:00:27,130 --> 00:00:29,440 Well, you can do the same with dictionaries. 6 00:00:29,950 --> 00:00:34,660 I can say, does Baskett exist in user? 7 00:00:35,470 --> 00:00:37,180 And let's print this out. 8 00:00:42,600 --> 00:00:45,900 And it's going to say, yep, basket does exist and user. 9 00:00:46,470 --> 00:00:49,770 What about what about size? 10 00:00:50,820 --> 00:00:51,660 Does that exist? 11 00:00:52,480 --> 00:00:53,500 No, that's false. 12 00:00:53,550 --> 00:00:59,090 That does not exist in user, but here is where it gets really interesting. 13 00:00:59,550 --> 00:01:04,790 And this, again, is a nother dictionary method that we can use. 14 00:01:05,220 --> 00:01:12,510 And by the way, you can see that there's not that many dictionary methods that, well, dictionaries 15 00:01:12,510 --> 00:01:12,780 have. 16 00:01:13,530 --> 00:01:15,690 Luckily, we're going to go over the main ones here. 17 00:01:16,700 --> 00:01:19,490 The one is called Ki's. 18 00:01:20,950 --> 00:01:26,840 And Keyes simply checks the keys, what are the keys of user? 19 00:01:27,130 --> 00:01:30,280 So if I go hello here and I click Run. 20 00:01:32,390 --> 00:01:41,000 Well, no keys, sorry, on this side, not this, so this is a value, so if I want to check keys, 21 00:01:41,000 --> 00:01:42,190 I'd say age. 22 00:01:44,190 --> 00:01:49,340 Which is true, but if I want to check a values well, in that case, if I do. 23 00:01:49,380 --> 00:01:49,950 Hello? 24 00:01:51,710 --> 00:01:58,160 I get true it's going to go over or what we call iterate over. 25 00:01:59,240 --> 00:02:08,120 The values, another one that's really useful is the items and items is special because we've seen keys 26 00:02:08,120 --> 00:02:13,510 and values, but items actually grabs the entire item. 27 00:02:14,300 --> 00:02:20,120 So the way we can actually see this is let's just remove and click run. 28 00:02:22,970 --> 00:02:34,160 This is interesting, I have DECT items here and I grab looks like a list, and in here we have a bracket 29 00:02:34,160 --> 00:02:38,270 basket one, two, three, great yellow and H20. 30 00:02:38,390 --> 00:02:43,970 But there's some weird syntax here that we haven't seen before, and this is actually a tuple. 31 00:02:44,180 --> 00:02:49,130 So we're going to hold off on this and talk about this a little bit more when we talk about our next 32 00:02:49,130 --> 00:02:49,970 data structure. 33 00:02:50,750 --> 00:02:57,780 But keys, values and items is an easy way for us to grab these things for us from our dictionary. 34 00:02:58,760 --> 00:03:01,970 Let's continue on with other dictionary methods that we might use. 35 00:03:02,690 --> 00:03:04,570 One is a very nice one. 36 00:03:04,610 --> 00:03:05,210 It's called. 37 00:03:06,740 --> 00:03:07,220 Clear. 38 00:03:07,940 --> 00:03:09,170 And if I run this. 39 00:03:10,810 --> 00:03:12,980 You see that I get an empty dictionary. 40 00:03:13,840 --> 00:03:19,840 What if I just run users clear here and run user? 41 00:03:22,230 --> 00:03:31,350 Well, it's still an empty object or an empty dictionary, so you can see here that clear doesn't actually 42 00:03:31,350 --> 00:03:32,570 return anything. 43 00:03:32,580 --> 00:03:38,040 It doesn't well is just in place, removes whatever the dictionary has. 44 00:03:38,050 --> 00:03:40,350 So it just creates an empty dictionary. 45 00:03:42,060 --> 00:03:42,750 What about. 46 00:03:43,710 --> 00:03:44,180 Copy? 47 00:03:45,420 --> 00:03:56,970 Well, a copy allows us to copy a user so that if I print user and user too, and I click run. 48 00:03:58,480 --> 00:04:05,470 I get two users each keys and values copy, but if I now let's say. 49 00:04:06,830 --> 00:04:10,610 Clear the first user and I click run. 50 00:04:12,080 --> 00:04:18,680 The first user is empty, but because I've copied the second user, the second user has the old information. 51 00:04:20,290 --> 00:04:22,570 And this is a concept that we've talked about before. 52 00:04:24,500 --> 00:04:34,280 Another useful command and let's just go back to having user is user dot pop, which removes a key and 53 00:04:34,280 --> 00:04:35,910 a value from the dictionary. 54 00:04:36,140 --> 00:04:42,310 So in our case, let's just say we want to remove the key that is age. 55 00:04:42,500 --> 00:04:43,820 So I'm going to say age. 56 00:04:44,270 --> 00:04:45,620 And if I run this. 57 00:04:46,830 --> 00:04:55,860 I get 20 because pop returns the value of whatever got removed, but if I do print user now, you'll 58 00:04:55,860 --> 00:05:00,000 see that age does not exist anymore because we've popped it off. 59 00:05:00,360 --> 00:05:04,860 But Pop, as you can see, removes the actual value. 60 00:05:05,920 --> 00:05:15,220 Or returns the actual value 20, here's another really fun one pop item, and honestly, this, I haven't 61 00:05:15,220 --> 00:05:20,590 used much, but I just think it's a fun one pop item, if you guessed well, you're not going to guess. 62 00:05:21,670 --> 00:05:28,300 Oh, and that's because I have to make sure I write it properly with lowercase if I run this. 63 00:05:30,450 --> 00:05:34,020 What just happened, it randomly pops up something. 64 00:05:35,090 --> 00:05:41,870 One of the keys and the values in this case, age 20, is removed, so the last item on the dictionary 65 00:05:41,870 --> 00:05:42,500 gets removed. 66 00:05:42,500 --> 00:05:45,670 But remember, a dictionary is unordered. 67 00:05:45,800 --> 00:05:52,310 So if this was a massive, massive dictionary that, well, doesn't have any order to it. 68 00:05:53,150 --> 00:06:01,120 Sometimes it removes some paire, as you can see, not the last one, but some pair of key value. 69 00:06:02,060 --> 00:06:04,100 So you have to be careful with this one. 70 00:06:04,100 --> 00:06:09,470 It doesn't necessarily just remove the last thing that you entered, but it might be useful on some 71 00:06:09,470 --> 00:06:09,980 occasions. 72 00:06:10,640 --> 00:06:13,130 Finally, we have something called update. 73 00:06:13,520 --> 00:06:18,220 An update simply updates, as the name suggests, a key value. 74 00:06:19,220 --> 00:06:20,840 So let's have a look here. 75 00:06:21,200 --> 00:06:24,920 All we have to do is give it a new dictionary. 76 00:06:24,920 --> 00:06:32,780 So curly brackets just simply say, hey, I want to update age to fifty five. 77 00:06:34,140 --> 00:06:35,550 Fight, click, run. 78 00:06:37,690 --> 00:06:40,960 Oh, and I forgot a bracket here, let's try that again if I click run. 79 00:06:43,010 --> 00:06:43,550 There you go. 80 00:06:43,700 --> 00:06:46,610 Age got updated, but if. 81 00:06:47,970 --> 00:06:56,250 This was a key that doesn't exist like ages and I click run, it will still update with a new key item. 82 00:06:57,250 --> 00:06:59,630 So this is another really useful method. 83 00:07:00,400 --> 00:07:02,710 All right, that's it for dictionaries. 84 00:07:02,770 --> 00:07:04,150 I'll see you in the next video.