1
00:00:00,180 --> 00:00:02,490
Now, let us briefly talk about dictionaries.

2
00:00:03,300 --> 00:00:08,250
So dictionaries are not that important for us in this course, but still they are an important part

3
00:00:08,250 --> 00:00:08,850
of Python.

4
00:00:09,240 --> 00:00:11,340
So I want to discuss it just a bit.

5
00:00:12,270 --> 00:00:17,910
So a dictionary in reality is, of course, something where you can look up a word, for example, and

6
00:00:17,910 --> 00:00:24,300
here it's a bit similar to dictionaries are related to lists and arrays, but they behave a bit differently.

7
00:00:25,200 --> 00:00:29,520
So let me just show you I will define just some dictionary and call it dictionary one.

8
00:00:30,030 --> 00:00:36,750
And you start and end the dictionary with these curly brackets and to just make it look a bit better.

9
00:00:36,780 --> 00:00:38,040
Let me write it down like this.

10
00:00:38,040 --> 00:00:43,560
So the syntax here is that you have some key words.

11
00:00:44,790 --> 00:00:49,770
For example, a property and I want to make this dictionary about cars.

12
00:00:50,640 --> 00:00:54,720
So the first dictionary should be about some mercy car.

13
00:00:54,930 --> 00:00:59,310
So the first property, the first keyword that I add here is brand.

14
00:00:59,910 --> 00:01:05,099
So the brand property will have to value could be a number or could be a string.

15
00:01:05,610 --> 00:01:14,070
And here it's string Mercedes, and then we can add other keywords and other properties.

16
00:01:14,280 --> 00:01:20,190
For example, the model and here the value is again, a string.

17
00:01:20,610 --> 00:01:28,410
And let's just take some car off Mercedes, and we can, of course, add other properties like color

18
00:01:28,710 --> 00:01:29,790
or year.

19
00:01:31,530 --> 00:01:35,370
The year is, for example, this one.

20
00:01:36,450 --> 00:01:43,440
So now we have a dictionary explaining or containing properties of our car.

21
00:01:44,460 --> 00:01:52,260
So if I run this, it is defined and now I can just call again the variable or the dictionary by writing

22
00:01:52,500 --> 00:01:52,800
one.

23
00:01:53,700 --> 00:01:56,460
And you see, this is what the dictionary now looks like.

24
00:01:57,510 --> 00:01:57,780
Sort of.

25
00:01:57,780 --> 00:01:58,620
Can we do with this?

26
00:01:59,160 --> 00:02:01,590
We can select certain entries.

27
00:02:02,280 --> 00:02:11,070
So the first idea may be to just call a property or, yeah, some feature of the dictionary by using

28
00:02:11,070 --> 00:02:13,680
it in the same fashion as a list or an array.

29
00:02:13,920 --> 00:02:17,160
So maybe you would write something like this.

30
00:02:17,910 --> 00:02:22,230
This would, you may think, would call this property here.

31
00:02:23,220 --> 00:02:30,420
However, it gives us an error because it tells us there's a key error, which basically means the key

32
00:02:30,660 --> 00:02:32,880
of one does not exist here.

33
00:02:33,900 --> 00:02:36,090
So this is not working.

34
00:02:36,090 --> 00:02:39,060
So for working

35
00:02:42,690 --> 00:02:48,810
and what we have to do instead, or is the correct way of calling a property of a dictionary is to not

36
00:02:48,810 --> 00:02:51,510
add a number here, but to add the key.

37
00:02:51,750 --> 00:02:58,470
For example, we could write model, and now it gives us the value corresponding to the key called model.

38
00:02:59,340 --> 00:03:01,590
So you see, this is the main difference.

39
00:03:02,230 --> 00:03:05,640
You have not anymore a list which is numbered.

40
00:03:06,060 --> 00:03:09,540
So the order of these features here doesn't matter at all.

41
00:03:10,290 --> 00:03:15,450
You have instead, instead of writing these indices, you have to write the key words here.

42
00:03:16,020 --> 00:03:21,060
So this can be really useful if you don't want to remember the order in which you have added all of

43
00:03:21,060 --> 00:03:24,930
these properties and you want to just search for a certain value.

44
00:03:25,620 --> 00:03:31,920
So it can be quite useful to use these dictionaries, for example, when you try to build a database

45
00:03:31,920 --> 00:03:32,490
or something.

46
00:03:33,750 --> 00:03:34,770
So what else can we do?

47
00:03:35,040 --> 00:03:39,870
We can, for example, write Dictionary one dot keys.

48
00:03:41,850 --> 00:03:43,920
And this would give us all of the keys.

49
00:03:44,100 --> 00:03:54,630
So all of these words here, and likewise, we can also write a dictionary one dot values, which would

50
00:03:54,630 --> 00:03:56,070
give us then only two values.

51
00:03:56,700 --> 00:04:04,110
And you see, it is an array or, yeah, this type or in this case, it's yeah, a collection of strings

52
00:04:04,110 --> 00:04:05,670
and also of numbers.

53
00:04:07,050 --> 00:04:11,850
And then last thing that I want to show you is how can you manipulate entries in the dictionary?

54
00:04:12,330 --> 00:04:18,570
And this is quite interesting because let me show you we can write a dictionary and then we do not drive

55
00:04:18,570 --> 00:04:20,220
the index, but we write the key.

56
00:04:20,850 --> 00:04:29,070
For example, a year and now I can write the year property should be 1996, which is different to the

57
00:04:29,070 --> 00:04:31,290
1995 that we have defined earlier.

58
00:04:32,430 --> 00:04:34,980
And let me at the same time, also change another thing.

59
00:04:35,610 --> 00:04:36,570
Dictionary one.

60
00:04:36,570 --> 00:04:39,960
And this time I will use a key which I have not defined so far.

61
00:04:40,110 --> 00:04:43,590
Country and country is Germany.

62
00:04:44,430 --> 00:04:49,710
And when I run both of these commands, let us see what the dictionary now looks like.

63
00:04:52,140 --> 00:04:54,600
You see brand and model still the same.

64
00:04:54,930 --> 00:04:59,760
The here has been updated from 95 to 96 and the country.

65
00:04:59,860 --> 00:05:07,170
Property has been added completely, so it means you can use the same syntax for changing the values

66
00:05:07,170 --> 00:05:14,130
corresponding to some key steps already exist and you can add new values and new keys if the keys do

67
00:05:14,130 --> 00:05:14,910
not exist.

68
00:05:15,930 --> 00:05:21,870
So as I might, as I said, dictionaries can be quite useful, but we will probably not use them in

69
00:05:21,870 --> 00:05:22,410
the course.

