1 00:00:00,009 --> 00:00:00,829 Welcome back. So if you 2 00:00:00,980 --> 00:00:03,710 listen, we talked about dictionaries, but now 3 00:00:03,869 --> 00:00:08,000 we're going to go a step further to talk about nested dictionaries. 4 00:00:08,010 --> 00:00:11,270 So basically dictionary inside of another dictionary. 5 00:00:11,710 --> 00:00:15,470 So far, we've been dealing with one single user info. 6 00:00:15,579 --> 00:00:20,229 But what if we had multiple users, right? How can we create this? So 7 00:00:20,610 --> 00:00:22,229 what I'm gonna do right here is let us 8 00:00:22,239 --> 00:00:25,670 change the name from user info to user credentials. 9 00:00:25,680 --> 00:00:26,219 All right, 10 00:00:26,440 --> 00:00:28,629 this is going to be the new name for our dictionary. 11 00:00:29,329 --> 00:00:31,510 And now curly braces, 12 00:00:32,359 --> 00:00:36,208 we can now add the very first nested dictionary 13 00:00:36,418 --> 00:00:39,028 that will contain the information for 14 00:00:39,238 --> 00:00:40,339 admin. 15 00:00:40,508 --> 00:00:41,019 So 16 00:00:41,770 --> 00:00:44,020 gonna come right here, type in admin. 17 00:00:44,270 --> 00:00:45,990 That will be our first user. 18 00:00:46,720 --> 00:00:48,490 And now the credentials, 19 00:00:48,720 --> 00:00:51,419 curly braces. Let's go with the password 20 00:00:52,900 --> 00:00:54,360 password in here 21 00:00:54,849 --> 00:00:55,430 and then 22 00:00:57,040 --> 00:00:57,819 call on 23 00:00:58,849 --> 00:01:02,349 and then we can go with uh admin 24 00:01:03,799 --> 00:01:06,110 123. 25 00:01:06,230 --> 00:01:06,730 All right. 26 00:01:06,940 --> 00:01:11,349 So the first user here admin, the password is going to be admin 123 27 00:01:11,459 --> 00:01:13,330 and we can add another 28 00:01:14,220 --> 00:01:17,239 credential, which would be the last log in. 29 00:01:18,629 --> 00:01:19,959 So last login, 30 00:01:21,449 --> 00:01:24,430 let's have this one in our coats, 31 00:01:25,260 --> 00:01:26,879 last log in 32 00:01:28,169 --> 00:01:29,309 and now colon, 33 00:01:30,069 --> 00:01:33,660 let's add the date So let's say something like 20 34 00:01:34,139 --> 00:01:39,209 24-10 dash 19. 35 00:01:39,629 --> 00:01:40,239 All right, 36 00:01:40,370 --> 00:01:45,620 just as an example, there is a bit of an error right here. Let me see. 37 00:01:45,629 --> 00:01:48,769 What exactly am I doing wrong? 38 00:01:49,389 --> 00:01:49,769 Ah 39 00:01:50,180 --> 00:01:53,250 Over here with password, the column should be outside. 40 00:01:54,069 --> 00:01:55,449 I made a mistake there. 41 00:01:55,580 --> 00:01:58,239 Ok. Much better. So this is the first and 42 00:01:58,419 --> 00:02:00,290 the dictionary we have admin 43 00:02:00,639 --> 00:02:04,419 that has the key value pairs, it has the key password 44 00:02:04,529 --> 00:02:06,809 and the developer password here is going to be admin 123. 45 00:02:06,919 --> 00:02:09,070 And then the other key here is going to be last login. 46 00:02:09,210 --> 00:02:14,199 And the value is of course 2024 1019, but we can add another dictionary. 47 00:02:14,210 --> 00:02:15,490 So I'm gonna say comma 48 00:02:16,130 --> 00:02:20,449 and now we can add another user, let's call this person user one. 49 00:02:21,029 --> 00:02:24,559 And I'm just gonna let Raley do the rest fill out 50 00:02:24,809 --> 00:02:26,850 all the information in there 51 00:02:28,119 --> 00:02:31,770 and there you go. So the password is going to be user 1123. 52 00:02:31,779 --> 00:02:36,710 And then last login is also now let's change the date here to something else. So 53 00:02:36,940 --> 00:02:39,330 let's go with 06 54 00:02:40,070 --> 00:02:41,360 and then maybe 55 00:02:41,539 --> 00:02:41,550 a 56 00:02:42,639 --> 00:02:45,190 14, all right, just for variety. 57 00:02:45,509 --> 00:02:46,199 And there it is. 58 00:02:46,210 --> 00:02:47,610 So this right here is what we refer to 59 00:02:47,619 --> 00:02:53,710 as a nested dictionary dictionaries inside of another dictionary. 60 00:02:53,789 --> 00:02:57,309 And of course, we can access the information pretty straightforward. So 61 00:02:57,470 --> 00:03:01,300 for example, if I wanted to print out the password 62 00:03:01,410 --> 00:03:03,460 for the admin, 63 00:03:03,729 --> 00:03:06,410 how can I do this? I can simply say print 64 00:03:06,919 --> 00:03:09,940 and now in brackets, I'm going to say user 65 00:03:10,600 --> 00:03:12,580 underscore credentials. 66 00:03:12,919 --> 00:03:14,179 Ok. And now 67 00:03:14,339 --> 00:03:15,820 the regular brackets 68 00:03:16,809 --> 00:03:20,369 and inside double codes, I'm gonna say admin. 69 00:03:20,970 --> 00:03:21,649 Ok. 70 00:03:21,899 --> 00:03:25,130 And now we want to print out what the password for the admin. So 71 00:03:25,369 --> 00:03:26,570 brackets again, 72 00:03:27,710 --> 00:03:28,649 let's add 73 00:03:29,000 --> 00:03:30,050 password 74 00:03:31,440 --> 00:03:33,240 and there it is. 75 00:03:33,250 --> 00:03:37,639 So if I run the program right now, you can see it says admin 123 because we're saying, 76 00:03:37,649 --> 00:03:40,899 hey, print out from the user credentials dictionary, 77 00:03:41,570 --> 00:03:43,350 we want you to print out 78 00:03:43,720 --> 00:03:45,350 the value 79 00:03:45,720 --> 00:03:51,470 of the key password belonging to the user admin. 80 00:03:51,779 --> 00:03:54,889 And that's why we have admin 123 81 00:03:55,089 --> 00:03:57,270 or I could say, OK, 82 00:03:57,630 --> 00:03:58,699 print 83 00:03:59,490 --> 00:04:01,190 and backet user 84 00:04:02,020 --> 00:04:07,559 credentials. And let's print out the last login for user one. 85 00:04:07,570 --> 00:04:09,919 How are we going to do this again? Very straightforward. 86 00:04:10,199 --> 00:04:12,559 I'm simply going to come in here, say user one 87 00:04:13,289 --> 00:04:14,029 and now 88 00:04:14,289 --> 00:04:21,350 new brackets and then simply put in the last login key last underscore 89 00:04:21,750 --> 00:04:22,470 login 90 00:04:24,290 --> 00:04:26,390 and there you go. So I run 91 00:04:26,760 --> 00:04:28,369 and there you go 2024 92 00:04:28,529 --> 00:04:30,869 06 14. 93 00:04:31,029 --> 00:04:35,630 So this right here is an example of nested dictionaries. And 94 00:04:35,779 --> 00:04:38,859 this can be particularly useful if you're trying to create 95 00:04:39,140 --> 00:04:42,119 functions or programs for firewalls or a 96 00:04:42,399 --> 00:04:46,079 password checking tool or a tool that check user credentials, things like that, 97 00:04:46,089 --> 00:04:46,420 right? 98 00:04:46,579 --> 00:04:50,529 You can use nested dictionaries for those kinds of programs. 99 00:04:50,630 --> 00:04:53,429 So thank you for watching and of course, I will see you in the next class