1 00:00:00,820 --> 00:00:01,280 Hi guys. 2 00:00:01,320 --> 00:00:06,310 Welcome back to another class of our course about them. 3 00:00:06,590 --> 00:00:08,720 So in this class it's very simple. 4 00:00:08,730 --> 00:00:15,360 My goal is to talk to you guys about another way that you can store your data as well as convert your 5 00:00:15,360 --> 00:00:16,820 data from one that I type. 6 00:00:17,250 --> 00:00:20,510 Well from one type of data to another type of data. 7 00:00:20,730 --> 00:00:27,090 So not only converting numbers into let's say certain strings but also converting certain strings to 8 00:00:27,180 --> 00:00:29,520 another types of strings. 9 00:00:29,520 --> 00:00:32,850 So it sounds maybe complicated but you'll see it's very very easy. 10 00:00:33,450 --> 00:00:37,230 So basically what we are going to talk about are dictionaries in Python. 11 00:00:37,230 --> 00:00:42,150 So what's what exactly is a dictionary in the normal world. 12 00:00:42,150 --> 00:00:48,990 So when let's say a real dictionary is basically a place where you can find out a word and the definition 13 00:00:49,020 --> 00:00:50,280 of words of this word. 14 00:00:51,360 --> 00:00:55,950 So it's gonna be one word linked with many words in Python. 15 00:00:55,980 --> 00:00:56,730 It's the same thing. 16 00:00:57,180 --> 00:00:59,400 So you guys will take one word. 17 00:00:59,400 --> 00:01:07,930 So it could be a string or a set of words and make it equal to let's say another set of words. 18 00:01:07,950 --> 00:01:12,430 So this is a way that you guys can store your data and also converter that as well. 19 00:01:12,450 --> 00:01:16,340 For example if you want to make a list of employees. 20 00:01:16,350 --> 00:01:21,840 So for example we can have no the number of each employee and you can have the name of the employee 21 00:01:21,900 --> 00:01:24,320 associated with his number. 22 00:01:24,330 --> 00:01:25,290 So in this case yes. 23 00:01:25,320 --> 00:01:29,930 As you can see this is a way that you can use dictionaries. 24 00:01:30,090 --> 00:01:38,580 So Michael today is really to present you this useful thing that you can use in Python and give you 25 00:01:38,640 --> 00:01:41,190 two examples of how you can use. 26 00:01:41,370 --> 00:01:48,370 Well this dictionary and those two examples well they can apply yet in everyday life. 27 00:01:48,390 --> 00:01:48,630 All right. 28 00:01:49,050 --> 00:01:51,460 So let's start first thing before. 29 00:01:51,570 --> 00:01:55,770 Well first thing that you guys can understand I have to understand is that dictionaries can store any 30 00:01:55,770 --> 00:01:58,520 type of data so it can be. 31 00:01:58,530 --> 00:02:02,820 It could be strings it could be numbers and they can convert. 32 00:02:02,820 --> 00:02:06,590 Well you can store a string with a number or a number with a string. 33 00:02:06,690 --> 00:02:09,020 You'll see it's a very very simple to use. 34 00:02:09,030 --> 00:02:09,720 All right. 35 00:02:09,720 --> 00:02:11,290 So let's begin. 36 00:02:11,310 --> 00:02:13,230 So how do you write down the dictionary. 37 00:02:13,410 --> 00:02:14,210 Well it's very simple. 38 00:02:14,220 --> 00:02:16,560 It's like writing down a variable. 39 00:02:16,560 --> 00:02:17,790 So it starts the same way. 40 00:02:18,120 --> 00:02:26,220 So let's say our dictionary will be named colors in this case will have our first example would be colors. 41 00:02:26,220 --> 00:02:28,440 Then you click on equal. 42 00:02:28,670 --> 00:02:35,280 Instead of writing down a sentence like you would do for a four when you are creating a variable you'll 43 00:02:35,280 --> 00:02:38,220 simply open up this parenthesis. 44 00:02:38,220 --> 00:02:42,630 So in this case those parentheses are used for dictionary. 45 00:02:42,630 --> 00:02:49,020 So everything that is inside of those parentheses will be all the words that we'll have for our let's 46 00:02:49,020 --> 00:02:50,250 say our dictionary. 47 00:02:51,360 --> 00:02:51,540 All right. 48 00:02:51,540 --> 00:02:56,390 So the first word that we are going to use as our dictionary will be blue. 49 00:02:56,820 --> 00:03:03,110 So we will generate Blue by simply the first letter of this word. 50 00:03:03,630 --> 00:03:08,070 So let's say B in this case will be equal to blue. 51 00:03:08,100 --> 00:03:12,070 So be two points in this case write it down like this. 52 00:03:12,330 --> 00:03:18,770 So B two points is equal to blue. 53 00:03:19,020 --> 00:03:19,870 So very important. 54 00:03:19,920 --> 00:03:21,250 This is your first word. 55 00:03:21,270 --> 00:03:23,740 So in this case this will be the key. 56 00:03:23,740 --> 00:03:26,050 And this is the same word. 57 00:03:26,100 --> 00:03:29,640 This is the word that is linked with the key. 58 00:03:29,890 --> 00:03:36,520 So you write down your word you're your first word the key right here and the second word will just 59 00:03:36,520 --> 00:03:37,030 be linked to it. 60 00:03:37,030 --> 00:03:42,550 So when you are going to make a search for inside your dictionary you're going to make a search for 61 00:03:42,610 --> 00:03:44,020 the word that is right here. 62 00:03:44,020 --> 00:03:47,190 And this is going to be your output. 63 00:03:47,230 --> 00:03:47,470 All right. 64 00:03:47,500 --> 00:03:48,840 So this is your first word. 65 00:03:48,850 --> 00:03:52,210 Let's say we want to add more more words in our dictionary. 66 00:03:52,210 --> 00:03:53,230 So very simple. 67 00:03:53,230 --> 00:03:56,140 You click on the comma and you add your second word. 68 00:03:56,170 --> 00:04:03,650 So in this case let's say want to do the same thing for red so write down are two points Red 69 00:04:06,570 --> 00:04:08,540 let's say wanted the same thing for orange. 70 00:04:08,730 --> 00:04:08,990 So. 71 00:04:09,100 --> 00:04:16,040 Oh we write down two points and we write orange. 72 00:04:16,040 --> 00:04:16,640 All right. 73 00:04:16,760 --> 00:04:20,300 So let's just Kip do those two words inside our dictionary. 74 00:04:21,200 --> 00:04:25,770 So as you can see each letter will refer to a word. 75 00:04:25,790 --> 00:04:28,790 So very simple we stored this inside of our dictionary. 76 00:04:30,740 --> 00:04:36,470 So another thing that you guys need to remember you can't have two letters that are the same so two 77 00:04:36,470 --> 00:04:37,930 keys that are the same. 78 00:04:37,940 --> 00:04:40,840 So in this case I can't have it be used two times. 79 00:04:40,840 --> 00:04:44,900 So let's say for example I tried let's say on a store before. 80 00:04:45,680 --> 00:04:46,720 I don't know. 81 00:04:46,780 --> 00:04:48,430 B for ball. 82 00:04:48,480 --> 00:04:49,970 So I want to add a ball. 83 00:04:49,970 --> 00:04:53,690 So as you can see it's not going to work because B is written two times here. 84 00:04:53,750 --> 00:05:00,010 And if you store the same let's say a word two times it's not going to work. 85 00:05:00,110 --> 00:05:01,350 So here for example it's B. 86 00:05:01,350 --> 00:05:06,830 So if I have two same values to same two keys that are the same. 87 00:05:07,410 --> 00:05:09,420 It's not gonna work. 88 00:05:09,870 --> 00:05:12,960 So you need to have two different keys. 89 00:05:12,960 --> 00:05:13,490 Great. 90 00:05:13,500 --> 00:05:18,720 So right now we have those three words and let's say our goal we want to fight what we want to look 91 00:05:18,720 --> 00:05:19,600 for. 92 00:05:20,010 --> 00:05:20,930 The word are. 93 00:05:21,030 --> 00:05:24,990 So imagine you have millions of words and you want to look for are right here. 94 00:05:24,990 --> 00:05:26,700 So how exactly would you look for. 95 00:05:27,120 --> 00:05:30,130 So the first thing that you guys will do is write down what print. 96 00:05:30,180 --> 00:05:37,020 Because we want him to be printed so they don't print we write them or a dictionary name which in this 97 00:05:37,020 --> 00:05:38,130 case is colors 98 00:05:41,600 --> 00:05:43,420 dot jet. 99 00:05:43,430 --> 00:05:47,820 So in this case does get here will have two values. 100 00:05:48,060 --> 00:05:50,940 So the first value will be the value that we are looking for. 101 00:05:50,940 --> 00:05:52,890 So in this case we are looking for B 102 00:05:56,180 --> 00:05:58,640 or r or any value that you want to look for. 103 00:05:58,640 --> 00:06:00,590 So let's say we are looking for a B. 104 00:06:01,250 --> 00:06:07,500 And the second value will be the default value so in this case let's say it's going to be stopped. 105 00:06:08,110 --> 00:06:10,860 So the default value is simply the value let's say. 106 00:06:11,530 --> 00:06:17,770 If for example the diction Python doesn't find the word in the dictionary he will return the default 107 00:06:17,770 --> 00:06:18,030 value. 108 00:06:18,030 --> 00:06:24,040 So for example let's say instead of b we have I don't know h and we don't have each and our dictionary. 109 00:06:24,040 --> 00:06:25,400 So python will return stop. 110 00:06:25,420 --> 00:06:28,060 So let's run the app and see what it looks like. 111 00:06:28,060 --> 00:06:30,600 So as you can see B stands for blue. 112 00:06:30,850 --> 00:06:32,490 So it returns blue. 113 00:06:33,070 --> 00:06:40,460 If for example instead of B will write down 0 which is orange we run our app as you can see it's going 114 00:06:40,460 --> 00:06:41,410 to give us orange. 115 00:06:41,440 --> 00:06:44,970 But let's say we write 0 with a capital letter. 116 00:06:45,070 --> 00:06:46,900 We don't have it in the dictionary. 117 00:06:46,900 --> 00:06:50,910 So as you can see it's going to generate stop because we don't have this value. 118 00:06:51,040 --> 00:06:55,720 And if we can generate let's say write down I don't know G for example we don't have it. 119 00:06:55,900 --> 00:06:57,460 So it's going to generate the same stuff. 120 00:06:58,090 --> 00:07:04,450 So the full value simply the value that is generated when the value of the word where the key doesn't 121 00:07:04,450 --> 00:07:05,570 exist in the dictionary. 122 00:07:06,250 --> 00:07:06,450 All right. 123 00:07:06,460 --> 00:07:10,360 So the second example that you get that we are going to do today is very simple. 124 00:07:10,360 --> 00:07:14,920 We will create employee numbers and we are going to look for those employees. 125 00:07:15,400 --> 00:07:24,220 So let's let's creates this basic app so let's have I don't know five numbers. 126 00:07:24,250 --> 00:07:28,310 In this case we'll have five numbers and give random names. 127 00:07:28,360 --> 00:07:30,010 So let's say. 128 00:07:30,450 --> 00:07:34,280 Name a. 129 00:07:34,440 --> 00:07:37,610 So a random number and a random name. 130 00:07:37,620 --> 00:07:40,930 So in this case the name B 131 00:07:47,390 --> 00:07:50,060 and let's say named C.. 132 00:07:50,210 --> 00:07:59,480 So my goal here is to present you that you can use dictionaries for names for names for strings as well 133 00:07:59,540 --> 00:08:00,790 as four numbers. 134 00:08:00,800 --> 00:08:05,930 So in this case we are going to use a dictionary for numbers and we'll find out numbers. 135 00:08:06,050 --> 00:08:08,600 Well we'll find out names by using numbers 136 00:08:11,350 --> 00:08:15,050 grip so let's do it. 137 00:08:15,540 --> 00:08:25,340 As I explained the here it's going to be names so I explain the formula to write this down the function 138 00:08:25,340 --> 00:08:26,660 to write this down is very simple. 139 00:08:26,790 --> 00:08:33,300 Simply write down names so your dictionary named dot get footnote up your parentheses. 140 00:08:33,450 --> 00:08:41,080 The first thing that you guys will write down will be your value your key sorry. 141 00:08:41,380 --> 00:08:52,350 So in this case it's gonna be let's say we are looking for a 150 to and the second thing since it's 142 00:08:52,440 --> 00:08:54,450 a number we keep it like this. 143 00:08:54,450 --> 00:09:03,770 And the second thing is the default value and in this case the default value will be let's say uh this 144 00:09:03,770 --> 00:09:07,870 name doesn't exist don't exist. 145 00:09:07,880 --> 00:09:11,720 All right and want to print all this 146 00:09:15,790 --> 00:09:16,360 here. 147 00:09:17,070 --> 00:09:23,960 All right so simply run the app and as you can see the number one hundred fifty two is then the A. 148 00:09:24,010 --> 00:09:32,370 If we change a number and write down some five for in this case it's gonna be the name D but let's say 149 00:09:32,370 --> 00:09:39,400 we write down 9 9 9 by some during us this name don't exist. 150 00:09:39,420 --> 00:09:39,830 Let's see. 151 00:09:39,820 --> 00:09:44,360 This is the definition of a dictionary in Python. 152 00:09:44,490 --> 00:09:46,540 You can see what is it exactly right now. 153 00:09:46,870 --> 00:09:49,650 And right now I think you can work with this. 154 00:09:50,250 --> 00:09:56,250 Well this thing that is a dictionary so that's it for this class guys and see in our next class.