1 00:00:00,570 --> 00:00:04,830 Now, let us understand some differences between the dictionaries and the list. 2 00:00:05,330 --> 00:00:10,760 Now dictionaries are like lists in many ways, but there are a few important differences. 3 00:00:11,040 --> 00:00:14,730 Point number one is dictionary items are not in any order. 4 00:00:15,150 --> 00:00:19,240 There is no Forestar last item in dictionary as there is no list. 5 00:00:19,680 --> 00:00:25,800 Second, as you can't concatenate dictionaries with the plus operator, if you want to add a new item, 6 00:00:25,800 --> 00:00:29,610 use indexing with the new TODAS list. 7 00:00:29,610 --> 00:00:34,780 Only have integer index values that range from zero to the length of the list minus one. 8 00:00:35,220 --> 00:00:41,490 But dictionaries can use any keys if you have a dictionary stored in a variable state where one you 9 00:00:41,490 --> 00:00:44,160 can store of value in where at the index. 10 00:00:44,160 --> 00:00:48,990 Three without needing values of the word zero or one or two. 11 00:00:49,260 --> 00:00:56,370 OK, now coming to adding or changing the items in the dictionary, you can also add or change value 12 00:00:56,370 --> 00:00:58,200 in a dictionary by using the dictionary. 13 00:00:58,210 --> 00:00:59,220 Giesen indexes. 14 00:00:59,620 --> 00:01:08,040 OK, for example, if we try to see the dictionary three is equal to we are giving here C then and the 15 00:01:08,040 --> 00:01:10,910 value for the same item. 16 00:01:11,430 --> 00:01:23,460 OK, now we are giving a print command and we are saying here dictionary three at the index, then we 17 00:01:23,460 --> 00:01:24,300 get the value print. 18 00:01:24,840 --> 00:01:34,770 Similarly, if we just say dictionary three and the index then is equal to say hacking, OK, and now 19 00:01:34,770 --> 00:01:42,440 we give up and command saying dictionary three index, then we get the value hacking. 20 00:01:42,900 --> 00:01:49,320 So this dictionary has an existing dictionary string value associated with the Gaetane that is Python, 21 00:01:49,530 --> 00:01:55,510 and we can assign a new value hacking to that using the same dictionary three and the index then. 22 00:01:55,680 --> 00:02:01,050 OK, now moving to using the land function with dictionaries. 23 00:02:01,050 --> 00:02:06,740 Now the land function shows the number of items in the list or the number of characters in a string. 24 00:02:07,140 --> 00:02:10,290 It can also show you a number of items in a dictionary. 25 00:02:10,290 --> 00:02:15,630 Also, for example, will enter something, an interactive shell to see how to use the land function 26 00:02:15,630 --> 00:02:19,010 to count items in dictionary, for example. 27 00:02:19,010 --> 00:02:23,350 Now we create a dictionary for and that is just open closed bracket. 28 00:02:23,370 --> 00:02:26,130 If we now use Lentulov Dictionary for 29 00:02:28,980 --> 00:02:30,390 megadeal and that's zero. 30 00:02:30,750 --> 00:02:37,770 Now suppose we say a dictionary for we give your key value see first and we give your value. 31 00:02:38,070 --> 00:02:39,970 C, a, b, c, ok. 32 00:02:40,920 --> 00:02:52,430 Now if we say another dictionary for C second as the key and the value for that is X, Y, Z, OK, 33 00:02:52,440 --> 00:02:58,820 we add another dictionary for the total and the value for that is eleven. 34 00:02:59,540 --> 00:03:04,870 OK, and now we give length of dictionary for we get that Dylanesque three. 35 00:03:05,100 --> 00:03:07,800 So the first line in this shows an empty dictionary. 36 00:03:07,890 --> 00:03:12,490 OK, the line function correctly shows the length of this empty dictionary as zero. 37 00:03:12,810 --> 00:03:19,230 However, after we introduce the following three values into the dictionary, the length function outdance 38 00:03:19,230 --> 00:03:24,230 three for the trachea and value base that we have just assigned to the variables. 39 00:03:24,570 --> 00:03:27,580 Let's move on to using the operator with the dictionary. 40 00:03:27,610 --> 00:03:32,700 Then you can also use the interpreter to see whether a certain key exists in the dictionary. 41 00:03:32,970 --> 00:03:37,110 And it's important to remember that the interpreter Chayefsky's are not values. 42 00:03:37,410 --> 00:03:39,390 OK to see this operator in action. 43 00:03:39,400 --> 00:03:42,840 We will enter the following an interactive shell for example. 44 00:03:42,960 --> 00:03:44,650 We creates a dictionary five. 45 00:03:44,940 --> 00:03:52,110 And here we give C one and colon C first item. 46 00:03:52,560 --> 00:03:55,260 Gamma C two. 47 00:03:55,560 --> 00:03:56,280 Second key. 48 00:03:56,760 --> 00:03:59,250 Colon C second item. 49 00:03:59,880 --> 00:04:01,970 OK, that is the values we have given. 50 00:04:02,310 --> 00:04:10,140 Now we give here for example the key C one in dictionary five. 51 00:04:10,530 --> 00:04:16,950 It gives us true or we give to in the dictionary five piguet true. 52 00:04:17,310 --> 00:04:24,420 Or if we give three in dictionary five it does fall because that is not existing. 53 00:04:24,930 --> 00:04:25,330 Right. 54 00:04:25,590 --> 00:04:37,030 Similarly if we give for example, C for not in dictionary five, that's true. 55 00:04:37,530 --> 00:04:42,810 So in this case, we have set up a dictionary called Dictionary Five with some key value pairs and then 56 00:04:42,810 --> 00:04:48,270 checks whether the key exists in the dictionary, using the interpreter, wherever it is existing, 57 00:04:48,270 --> 00:04:52,130 it gives us the value proof, wherever it does not forget the value is false. 58 00:04:52,440 --> 00:04:54,750 OK, similarly feels not an operative word. 59 00:04:54,750 --> 00:04:56,790 The value is not existing in the dictionary. 60 00:04:57,060 --> 00:04:59,630 We again get the value of the existing commander. 61 00:05:00,140 --> 00:05:05,780 Through not coming to finding the items is faster with a dictionary than what list. 62 00:05:06,110 --> 00:05:08,690 So now let us create a list and a dictionary. 63 00:05:08,810 --> 00:05:18,080 OK, now, for example, let's create your own list, one that is equal to see fighting one war hacking 64 00:05:18,740 --> 00:05:19,370 C. 65 00:05:21,230 --> 00:05:31,650 Intermediate and recreate dictionary six, that's equal to we are giving your say, let's give value. 66 00:05:32,240 --> 00:05:33,550 We will change the keys. 67 00:05:33,890 --> 00:05:36,650 So let's give Saiki one as zero. 68 00:05:37,340 --> 00:05:42,080 Then let's give key to and that is also zero. 69 00:05:42,230 --> 00:05:43,940 And then let's give you three. 70 00:05:44,520 --> 00:05:46,190 And that is also zero. 71 00:05:46,640 --> 00:05:48,080 OK, now. 72 00:05:48,970 --> 00:05:55,420 Python can basically evaluate the expression, that is, if you give a particular value in the dictionary 73 00:05:55,420 --> 00:05:59,410 value, which is more faster retrieval than your list value. 74 00:05:59,560 --> 00:06:06,010 OK, now this is basically because for a list, Python must start at the beginning of the list and then 75 00:06:06,010 --> 00:06:10,260 move through each item in order until to find a particular item. 76 00:06:10,510 --> 00:06:14,440 If the list is very large, Python must sort through numerous items. 77 00:06:14,650 --> 00:06:16,630 A process can take a lot of time. 78 00:06:16,870 --> 00:06:22,270 What a dictionary is also called as a hash table directly translates where the computer's memory and 79 00:06:22,270 --> 00:06:24,220 the value for the key value is stored. 80 00:06:24,220 --> 00:06:29,470 Which is why dictionary items don't have an order no matter how large a dictionary is. 81 00:06:29,470 --> 00:06:35,590 Finding any item always take some amount of time, same amount of time, because this difference is 82 00:06:35,590 --> 00:06:41,510 speed that is hardly noticeable when searching a short list or short dictionaries for that case. 83 00:06:42,020 --> 00:06:49,240 OK, now let us understand using the loops for dictionaries so you can also iterate over those keys 84 00:06:49,240 --> 00:06:54,280 in the dictionary using for loops, just as you can get rid of the items in the list. 85 00:06:54,580 --> 00:07:02,290 OK, now, for example, we have this dictionary six created, which takes four key one in dictionary 86 00:07:02,290 --> 00:07:02,770 six. 87 00:07:02,960 --> 00:07:13,750 OK, and here we give print command and we give print the value of given and dictionary six. 88 00:07:13,900 --> 00:07:18,850 Add the index geva so we get that given value. 89 00:07:18,850 --> 00:07:21,560 Zero two zero three is also zero. 90 00:07:21,580 --> 00:07:23,290 So all the values are being printed. 91 00:07:23,470 --> 00:07:30,220 OK, so to use a false statement to iterate over the keys in a dictionary starts with the four key word 92 00:07:30,500 --> 00:07:36,710 against the variable key one using the N word to specify that you want to loop over the dictionary six 93 00:07:36,760 --> 00:07:38,530 and end the statement with the column. 94 00:07:38,860 --> 00:07:43,990 So as you can see, after entering the print, come on, it returns each in the dictionary along with 95 00:07:43,990 --> 00:07:45,970 its corresponding values.