WEBVTT

00:01.820 --> 00:03.860
Let's go learn dictionary.

00:04.310 --> 00:05.600
Let me create a new file.

00:05.630 --> 00:10.280
Name it dictionary dot Pi.

00:10.430 --> 00:12.650
Here I'm going to create a dictionary.

00:12.680 --> 00:13.400
Okay.

00:13.970 --> 00:18.530
And I have to tell you dictionary has keys and value.

00:18.560 --> 00:21.530
And also a dictionary is a collection okay.

00:21.530 --> 00:27.170
Which is unordered, changeable and indexed.

00:27.410 --> 00:34.370
In Python, dictionaries are writing with curly brackets and they have keys and also values.

00:34.370 --> 00:36.080
So let's go and see that.

00:36.170 --> 00:41.990
For example I have um a table of friends.

00:42.020 --> 00:45.380
Okay friends.

00:46.190 --> 00:50.150
And it is equal to we use curly bracket okay.

00:50.180 --> 00:52.250
Here we use for example name.

00:53.060 --> 00:56.420
And then here we use colon.

00:56.420 --> 01:02.340
And for example name is going to be name at and use schema to separate this.

01:02.370 --> 01:04.380
Now this both okay.

01:04.410 --> 01:06.360
Name and these two.

01:06.390 --> 01:09.240
These are one element now okay.

01:09.240 --> 01:10.230
This is the key.

01:10.230 --> 01:12.690
And this part is the value.

01:12.960 --> 01:16.470
And then we have for example last name.

01:17.940 --> 01:22.710
So last name is for example in Richmond.

01:25.110 --> 01:29.790
And we have date of birth okay.

01:31.830 --> 01:36.300
So date of birth is going to be for example 30 or.

01:36.330 --> 01:39.900
Let's use this one okay.

01:39.930 --> 01:42.210
Now I have a dictionary okay.

01:42.240 --> 01:45.090
That contains keys and values.

01:45.120 --> 01:47.610
And now I can print this okay.

01:47.640 --> 01:48.930
So let's print it okay.

01:48.930 --> 01:51.330
Print friends.

01:53.370 --> 02:00.140
And let's see if it is giving me the keys for the values or both.

02:00.830 --> 02:01.520
Okay.

02:01.550 --> 02:02.570
Python.

02:04.100 --> 02:12.530
And as you see right now, it is giving me the names and also sorry the keys and also the values.

02:12.560 --> 02:13.250
Okay.

02:13.520 --> 02:19.970
So how I, how I can get to this.

02:20.000 --> 02:20.270
Okay.

02:20.300 --> 02:25.460
How can I print for example, uh, only the name.

02:25.970 --> 02:26.420
Okay.

02:26.450 --> 02:27.500
How can I do that.

02:27.500 --> 02:29.180
So let's use here.

02:29.180 --> 02:35.960
For example I have a key and name of key is name okay or last name.

02:35.960 --> 02:41.540
So now let's I'm accessing the values using its key.

02:41.720 --> 02:43.490
Now I have friends okay.

02:43.520 --> 02:44.300
It has a key.

02:44.330 --> 02:47.660
Key is name and its value is name.

02:47.900 --> 02:48.560
Okay.

02:48.650 --> 02:51.560
Now let's see if it is giving me or not.

02:54.110 --> 02:58.100
As you see it is giving me a value for name.

02:58.320 --> 03:04.740
Also, if I ask for DOB, which is date of birth.

03:05.430 --> 03:08.250
Again, it is giving me the date of birth.

03:08.280 --> 03:16.590
Okay, so that is how you can print a the one element from a list.

03:17.700 --> 03:27.300
And also we can use loop to go to go through and print keys and also values.

03:27.300 --> 03:33.480
And by using a function called item built in function called items.

03:33.510 --> 03:34.080
Okay.

03:34.110 --> 03:36.030
So let's go and see that.

03:39.060 --> 03:43.560
Let's use for x and y okay.

03:43.920 --> 03:50.340
And friends dot we have a built in function for this.

03:50.370 --> 03:53.070
It is items okay.

03:53.100 --> 03:54.630
Now we have this.

03:54.630 --> 03:58.910
And right here I'm going to print X and y.

03:59.270 --> 04:04.940
So let's save this and execute the program.

04:04.940 --> 04:07.970
As you see we have name which is name.

04:08.000 --> 04:14.120
And last name and date of birth is 1998.

04:14.150 --> 04:14.750
Okay.

04:16.220 --> 04:21.260
So this is how we can print both of them.

04:21.290 --> 04:22.640
And.

04:24.650 --> 04:32.840
Uh, what else I can tell you we can use condition, but you haven't learned anything about condition

04:32.870 --> 04:33.500
yet.

04:33.710 --> 04:39.710
And we will cover those later on.

04:39.740 --> 04:40.250
Okay.

04:40.280 --> 04:47.630
So here you learn how to print, uh, a value using its key and also how to print both of them.

04:47.630 --> 04:51.830
Key and value for uh, using for loop.

04:51.830 --> 05:01.170
And also we can, uh, concatenate some text here for example, I can say here, okay, while printing

05:01.170 --> 05:03.870
I am going to print a text as well.

05:03.900 --> 05:08.280
I will say key is equal to this one okay.

05:08.310 --> 05:09.990
And then concatenate this.

05:09.990 --> 05:19.680
And then right here I can say value and concatenate that one too.

05:19.830 --> 05:24.540
Now it is I am able to concatenate because this one is a string.

05:24.540 --> 05:26.280
And also this one is also a string.

05:26.280 --> 05:28.830
So string with string can be concatenated.

05:28.860 --> 05:35.370
But if some of them could be integer so it's not able to be concatenated.

05:35.430 --> 05:36.000
Okay.

05:36.570 --> 05:40.620
Now you see key is equal to name and value is equal to name.

05:40.650 --> 05:43.800
And what if I change this to integer.

05:43.830 --> 05:45.450
Let's change it to integer.

05:45.480 --> 05:47.040
Now you see there is.

05:47.100 --> 05:48.960
It will give you an error.

05:49.380 --> 05:51.690
And that is here.

05:52.320 --> 05:54.600
You see it is printing.

05:54.600 --> 05:59.270
The first line is printing the second line, but only is coming to the last one.

05:59.300 --> 06:06.440
It is telling you that you can only concatenate string with string, not integer with string.

06:06.440 --> 06:08.210
So how can I do that?

06:08.240 --> 06:09.890
How can I solve this?

06:10.250 --> 06:16.040
As you see, the key itself is a string and the value is integer.

06:16.040 --> 06:19.040
So here I can change it okay.

06:19.220 --> 06:21.980
Using okay I can cast this okay.

06:22.010 --> 06:24.830
I can use it in str function.

06:25.250 --> 06:30.800
And now the problem will be solved is this is one way that we can do.

06:30.830 --> 06:33.950
Or we could change this back to string.

06:33.950 --> 06:36.950
So we don't need to use str right here.

06:37.490 --> 06:46.850
And that is how we can create our dictionary and how we can use it to print the data and a lot of things.

06:46.880 --> 06:47.570
Okay.

06:47.570 --> 06:50.540
So through the course we will be using this a lot.

06:50.540 --> 06:53.690
And you will learn this with a lot of information.

06:53.720 --> 06:54.980
So see you.
