Hello guys.
So we are going to continue the discussion with respect to Python.
And now we are going to discuss about our new data structure which is called as dictionaries.
So in this video this is the entire video outline where we will be discussing about the introduction
to dictionaries.
We will be creating dictionaries with the help of Python.
How to access the dictionary elements, modifying dictionary elements.
Then we'll be seeing some of the amazing dictionary methods that we usually use while we are developing
projects.
Along with that, we'll also be iterating over dictionaries.
Then we will be discussing about nested dictionaries, then dictionary comprehension.
And finally we will be seeing some of the common errors that we usually face.
Now in this it is very much important that we probably do a lot of practicals.
So that is the reason I will be showing you each and every thing with the help of coding.
Now let me go ahead.
And first of all, uh, let's see the definition of dictionaries.
So dictionaries are nothing, but it is an unordered collection of items.
The store data in key value pairs.
Okay.
So they're all the data is basically stored in key value pairs.
Key must be unique and immutable.
So once you specifically define a key it cannot be changed.
Values can be changed and key must always be unique, okay?
And it can include strings, numbers or tuples uh which while values can be of any type okay.
So let me just go ahead and I hope you have just understood the definition.
But again to make you understand much more in a better way, first of all, we will go ahead, uh,
in discussing about creating dictionaries.
Okay.
Now with respect to creating dictionaries, first of all, what we are really going to do over here
is that create an empty dictionary.
Now, already, you know, if I use square braces okay.
And before that make sure you select the kernel.
Uh, so if you are basically using this square brackets then you basically create an empty list.
If you are using tuples you create an empty tuple.
Now in case of dictionary we use flower braces okay.
Now now let's go ahead and define and create our empty dictionary.
So here you can see if I go ahead and print type of empty dictionary, you will be able to see that
I will be getting a class which is called as dictionary.
So in order to create an empty dictionary, all we have to do is that we have to specifically use this
flower braces.
Okay.
Another way how we can actually create our empty dictionary is that by using this dict class okay.
And here we will initialize it as a method.
So once we initialize it here you'll be able to see.
Now again I will be getting an complete empty dictionary okay.
So right now it is a complete empty dictionary.
So these are the two ways of specifically creating an empty dictionary Now, as I have already said,
that dictionary is all about key value pairs.
Right now, whenever we talk about key value pairs, let me just give you an example.
So key.
So initially we will you start writing in this flower brackets.
So first of all what we are going to do is that we are going to give my key name, let's say one of
the key name with respect to student information is name.
And let me just go ahead and write the name called as Krish.
Okay.
So Krish is the name.
So this basically becomes the key.
This basically becomes the value.
Okay.
Now the next thing is that I will go ahead and use my another key which is called as age.
Okay.
And here we are specifically going to use a value let's say 32 okay.
Third I'm just going to use another key which is called as grade.
Now if I go ahead and write this you'll be able to see if I go ahead and print this student.
This is a complete dictionary where I have three keys, that is name, age and grade, and the values
are crush 32 and 24.
Now if I go ahead and print the student.
So this basically becomes my entire dictionary right?
Which has this key value pairs.
If you want to also check out the print off type of student, you will also be able to see that I'm
able to get a dictionary over here.
Okay, so this is how you specifically create a dictionary with the help of key value pairs.
Okay.
Now let me just show you one more thing here.
When do you get an error.
Because as I said you that key should be unique okay.
So let's say if I go ahead and copy this and paste it over here and again I use the same name.
Now what is going to happen.
Okay.
And I'll just go ahead and print student.
Let's see what is going to happen.
Because you really need to understand whether we will get an error or whether it will just print out.
So here you can see only two keys are basically getting their name and age right.
Name is having the value of 24.
Age is 32.
Now what has exactly happened over here?
Now when I'm writing name is equal to Krish.
This was one of the key that I have already defined.
Now, if I'm again defining this particular key, you know, in the upcoming like or in the key value
pairs, then what it is going to do, the value is getting going to get replaced.
Okay.
But it is going to consider as one key itself.
So which is the recent value that you have replaced over here, the value that is what is getting displayed.
So always please make sure that here you don't have to always create the key with the same name.
I'll not say this as an error, but here you can see that, uh, I can just write.
Single key is always used okay.
Instead of multiple keys.
So this is one super example.
And this will be very much important because see, um, if you know about databases now NoSQL databases
like MongoDB, like Cassandra over there, all key value pairs will be specifically used, right?
All your data will be stored in key value pairs.
So it is important that we always need to have this key unique.
Right now let me just go ahead and let me talk about accessing dictionary elements okay.
Now with respect to accessing dictionary elements.
Now what I'm actually going to do, let me just go ahead and make this as, uh, I'll just copy this.
Okay.
And let me copy this over here.
Oops.
Not here.
Sorry.
Here.
And let me just make this grade as a.
Okay.
Now, this is my entire dictionary, right?
Now, if I want to access any value, let's say I want to access the value of grade.
Okay.
Now how do I do it?
We definitely have to use this key.
So what I will be doing is that I will just say student of I want the grade of this particular student.
So I will just give the key name over here and let me just go ahead and print it.
Okay.
So here, once I do the print over here right, I should be able to get to see the grade.
Similarly, let's say I want to go ahead and get the age.
So I will go ahead and write student of student of age.
Right.
And if I go ahead and print it it is 32.
Right.
So this is one of the method of accessing I'll write it down over here accessing dictionary elements.
Okay.
This is one of the easiest way to probably do it.
There is also one way where we will be able to access the values using the default get method that is
provided by the dictionary.
Okay, get method that is provided by dictionary.
Now how to do this, I will just show you.
Okay, so first of all I will just go ahead and write Print.
Let's say I want to get the grade right.
What is the grade of this particular student.
So I will just go ahead and use Dot get.
And here I'm just going to give my key name that is dot grade okay.
Similarly let's say if I want to go ahead and print student dot and uh, let's say I want to probably,
um, you know, let's say that there is no, like over here.
The key that are available are name, age, grade.
Right.
Let's say I will go ahead and search for last name.
Okay.
I know the key is not present over there.
So let's see what is the value that I will be getting okay.
And by using get we will be able to get the value anyhow.
But if I execute it here you'll be able to see first student grade.
I got a student age.
I got 32 again.
When I'm writing student dot get of grade, I can get a.
But when I'm searching for last name, I'm not getting anything right.
I'm getting it as none.
Now let's say that, uh, if I find out if I don't find any key, I want to probably give a default
value.
So for that I will go ahead and write print student student Dot.
Get.
Okay.
And here I'm going to specifically write last underscore name I know last number underscore name key
is not available.
But I will give a default value if it is not available.
So I'll write not available.
Now let's see the value that we are going to get.
So see over here.
Last name was not present in this particular key.
So I am getting the default value which I have provided it over here as not available.
So before it was giving us none.
Now it is probably giving us not available.
Right?
So this is how with the help of key, you will be able to access it.
And two ways I have actually shown you how to access dictionary elements.
Either you are directly calling the key or you are using the Get method right.
Now let me just go ahead and let me talk about the next method that is called as modifying dictionary
elements.
Okay.
Now with respect to modifying dictionary elements, one very important key that I really want to write,
right?
Dictionary are mutable right?
So you can add, update, update or delete elements.
Okay, so this is the most important thing about dictionary.
But you cannot see.
You cannot like always all the time.
Your key needs to be unique right at any point of time.
So let me just go ahead and show you some of the examples over here.
So let us go ahead and discuss about modifying dictionary elements.
Uh, so here uh, already, uh, let us go ahead and print this students.
Right.
And, uh, here you can see the name is the key.
The key name, uh, is basically having the value crush age is 32.
Grade is a.
Now let me do one thing.
Let me just go ahead and, uh, add a new key.
I'll also be showing to add a new key and also updating let's say age.
So here now if I go ahead and write student of age and let's say the age is now 33.
Okay.
And uh, I'm just going to print the student now along with that, what I am actually going to do is
that I'm going to add a new key.
And the new key will be something like address.
Okay.
And let me just go ahead and write the address as India.
Okay.
So this is the new key that I'm specifically adding.
Now I will go ahead and print the student.
Now here you can actually see that the first key age has got updated to 33.
Now once it got updated I again added a new key over here which is called as address.
So now I will be able to see the address India that has been added to the same, uh, student dictionary.
Okay.
Along with this, uh, we can also go ahead and delete any key.
Right.
So what I'm actually going to do is that I'm going to delete the key over here.
Okay.
Let's consider that I'm going to delete the grade key.
So let's go ahead and see that.
So here what we have actually done we have updated the value for the key Right here we have added a
new key and value, added a new key and value.
And in the next statement, what I'm actually going to do is that I'm going to delete the key.
So in order to delete the key I just need to use this del keyword okay.
That is available in Python and I will be using the student.
And let me just give the key name.
So if I go ahead and write like this, this will basically delete the key and value pair.
Okay.
Now if I go ahead and print the student, you will be able to see that I will now have the entire key
right?
Grade has got deleted along with the value, and I just have the remaining key that is key value pairs
like name crush, age 33 address India.
Okay, so this is how you delete the key value pair.
So these are some of the operations and how we can modify dictionary elements.
Okay.
Um now let me just go ahead and show you some of the dictionary common dictionary methods that we use.
Okay.
Now you'll be also seeing more examples because after this I will be also showing showing some use cases
examples okay.
So there again we will be discussing more about dictionaries okay.
Now some of the important dictionary methods okay.
So first of all let me just go ahead.
Let's say you just want to get the all the keys of that particular dictionary okay.
So I will go ahead and write keys is equal to student which is my dictionary student dot keys.
Okay.
And let me just go ahead and print all the keys over here.
Okay then let me just go ahead and write.
Values is equal to student dot values.
Okay.
If I want to get the values right off all the dictionary that I have basically in the dictionary, all
the values that I if I want all the values, how can I get it?
So this first code that I've actually written, this will actually help you to get all the keys.
Okay.
And this will actually help you to get all the values okay.
And if I go ahead and print the values I will be able to see the values over here.
Uh, one more.
Uh, let's say I want to get all the key value pairs, let's say in the form of three items.
Okay.
How do I get the key value pairs right in that case.
So let me just go ahead and write.
And I'll define a variable called as items.
And if I go ahead and write student dot items right.
And this will actually help me to get all key value pairs.
Okay.
Now let me just go ahead and print this specific items.
Okay.
So here you can see that uh let's see the first one okay.
Student Dot keys I'm getting all the key.
So name, age and address are the key.
When I wrote student dot values I got all the values.
I'm printing it.
So Krish 33 and India.
And when I want all the key value pairs.
So like this I'm able to get it right.
So this will be a new type which is called as dictionary items which will be in the form of list of
tuples.
So these are nothing but tuples right.
Tuples tuples tuples.
Right I will be able to access this particular tuples also.
And it is a list of tuples okay.
So here you can see name Chris age 33 A address India.
Right now one more thing.
Uh, I really want to do is do a shallow copy.
Okay.
Now let us discuss about shallow copy over here.
So, guys, now let me just go ahead and show you the working of shallow copy.
And this is something really, really important.
And trust me, you should never do this mistake.
Whenever you are implementing in any kind of project, you have to make sure that whenever, uh.
And you need to remember this concept because this can be a very small mistake whenever you're developing
projects.
Okay, now I have student dictionary over here right now.
Let me do one thing.
Let me create another variable.
Let's say I will go ahead and write student underscore copy.
And I will assign the student value over here.
And as you all know what is present in the student the key value pairs.
Right now if I go ahead and print student, and if I go ahead and print student underscore copy okay.
Student underscore copy.
What am I getting?
I'm getting the same value.
This is perfectly fine.
And obviously since I'm copying this particular value to another variable.
So this will also be a dictionary that will be having the same value over here okay.
Okay.
But now what I will do I will just go ahead and take student name value.
Right.
Student name value.
And I will assign some other value itself.
Right.
Let's say crush one okay.
Now let me just go ahead and print student and let me print the same student underscore copy.
What do you think should be the name in student underscore copy?
Should it be Christian or Christian?
Okay, I'll make it to Christian.
Okay.
Let's say I'm changing the name of this particular student right over here to Cristo.
Now, since I'm making the change to this student dictionary, since I made a copy of this in student
underscore copy, then you may be thinking, okay, student underscore copy should still have Christian,
but it does not happen in that way.
If I go ahead and see the output, you'll be seeing that since student also got the name as Krish two
since we had assigned the value to student underscore copy.
So here also we are getting Krish two.
And this is a big problem right?
So how do I make a separate copy.
You know whenever I probably want to make a copy for this particular dictionary to an another variable
in such a way that after that if I update this, the same update should not happen in your copy variable.
So for that I will be showing you about shallow copy.
Now in shallow copy, what we do is that let's say I go ahead and create my student copy one variable.
I will go ahead and write student dot copy function.
Okay.
Now this copy function is responsible for doing the shallow copy over here.
In short if you really want to understand this will basically allocate a different memory.
It will take this variable and it will give the reference of this variable to an another memory, which
will have that entire value that we really want to store.
Okay.
Now if I go ahead and print student underscore copy student underscore copy one okay.
And if I go want to go ahead and print student.
Right.
And if I execute it now here you can see, okay, I'm having the same value.
But now let me just update the student name, okay.
If I go ahead and update the student name, let's say if I go ahead and write Chris three okay.
Now if I go ahead and print both of them, will I get the same value of the name?
The answer is no.
See, I will execute this now in my student underscore copy one.
I still have Chris two and student I have Chris three.
Right.
And why this was possible because of the shallow copy itself.
Right.
So just get an idea about shallow copy.
Uh, shallow copy in turns, you know, provides a different memory location so that whenever we change
one of the variable, it should not impact the other one.
Okay.
So just a smaller thing to understand over here because this will be important when you are doing the
coding.
Now let's go ahead and discuss about iterating over dictionaries.
Okay.
First thing you can use loops to iterate.
Like how did we do in the in the in the case of list or in the case of tuples.
So here also we are specifically.
Okay I'll write.
You can use okay loops to iterate.
And we can iterate over dictionaries.
And you know in dictionaries.
Uh, if I probably talk about we have keys, we have values or we have items.
Items basically means the combination of key and value pair, right.
So let me just go ahead and show you the same example.
Let's say that this is my student variable okay.
And for this particular student I will go ahead and iterate through each and everything.
So first of all I will try to show you iterating over keys okay.
Now iterating over keys for keys in again we'll use a for loop and I will just go ahead and write student
dot keys.
When I write student dot keys, obviously you'll be able to see that I'll be getting the keys itself.
If I go ahead and print the key, you'll be able to see.
Oops.
Uh, keys.
Sorry.
You'll be able to see name, age, and address.
These are the keys that I have actually defined.
Similarly, you can iterate iterate over values, and for that what you need to do again, copy the
same thing.
Right?
Paste it over here instead of student dot keys.
Now you go ahead and write student dot values.
Okay.
And once I go ahead and write it over here I can print it over here itself.
And this is what you will be able to get a value Chris three.
You'll be able to get 33 India.
Okay, now if I want to iterate, iterate over key value pairs, then what we really need to do I will
be using two variable in my for loop.
One is key, comma value and student dot items.
And now I will just go ahead and print by using an f string.
Okay.
So this is one way of formatting.
Um in sprint formatting I can go ahead and write my key.
Along with this.
I can go ahead and write my value if I go ahead and see this.
This is my age.
Three age.
Uh, sorry.
Name Chris three, age 33.
Address India.
So you can also iterate over the key value pairs.
And just by writing string dot items, you get that value in tuples right in list of tuples.
So all these things you can basically work and you can basically iterate over the dictionaries.
Now talking about the next one, uh, here we are going to go ahead with let me make some cells.
Okay.
So we are going to talk about nested dictionaries.
Okay.
Now nested dictionaries.
A dictionary inside another dictionary okay.
And usually if I talk about databases MongoDB.
Right.
NoSQL database over there.
Everything is stored in key value pair.
Whenever we say key value pair later on we can read that convert that into a dictionary.
And I may have any number of records in the MongoDB database.
Right.
So let me just go ahead and do one thing.
Let me go ahead and write students, and let me just show you how you can create key value pairs.
Okay.
So let's say this is my first key.
That is nothing but student one.
And I will just go ahead and write my key value pair here.
The first thing I will go and see name name is let's say Krish.
Uh, age is.
Let's say colon 32.
Okay.
And, uh, age 32.
And here I am specifically creating this.
Right.
Sorry.
It should be colon not equal to colon 32.
Okay.
This is my first record.
Huh.
Now let me go ahead and create my second record.
Let's say I may have student two data And now with respect to this particular student two data, I may
have name.
Name is nothing but let's say fresh or I'll just say, um, Spider-Man or Peter Parker or anyone.
Right?
So Peter.
Right.
Age is nothing but let's say 35.
Right.
So here you can see key value pairs.
Right.
And this is nothing.
But this is basically a nested dictionary.
Right now if I go ahead and print students you will be able to see that hey it looks like a dictionary.
Key value pairs.
Again it can have nested key value pairs.
Right.
But these are just like a kind of records like how we uploaded in MongoDB or in any other NoSQL database,
NoSQL databases right now.
How do we access this?
Nested dictionaries access nested dictionaries, dictionaries, elements.
Okay.
So I will just go ahead and print right students.
And here I'm going to use, let's say I want to read The Age of Peter Parker.
Then how do I write?
So I will just go ahead and write.
Student uh.
Student two okay.
And the next bracket will be specifically name okay or name or age.
I can also get name if I want to print, I can print name.
Let's say if I go ahead and print this entire information along with age, here I will be getting age
or name of Peter Parker.
And and here I'll be getting the age right.
So if I go and see Peter and 35 right.
So here with respect to the nested dictionaries, also like how we read in in nested list.
Similarly we can go ahead and do that here.
The main thing is that we only have to call the key names, and automatically you'll be able to get
the value names right.
So this is one amazing way of playing with nested dictionaries.
Okay.
Now uh, again, you can try multiple example.
You can create your own nested dictionaries, any level of nested dictionaries.
Uh, there is no limit as such inside name.
Also, you can again go ahead and create another nested dictionary if you want.
Okay.
Now let me just go ahead and show you one more thing iterating over nested dictionaries.
Okay.
Now for let's say I will go ahead and write for student underscore ID.
Okay.
Since I require ID and information.
So let's say I will go ahead and write like this.
Just see this okay.
Student underscore info okay I will consider this as ID and this as the entire info okay.
And if I go ahead and write students students students okay Okay.
Dot items.
So what will student dot item give me if I go ahead and execute a code over here?
What will students dot items items give me.
It will give me dictionary in the key value pairs.
Right.
Like student one will be one key and this will be a entire value right inside this.
This can be a key and this can be a value, but it will be giving you in this particular format.
Now if I iterate over this nested dictionary, this I will consider as my id, and this will I'll consider
as my value.
Right.
So that is the reason I've written from student underscore ID and student underscore info.
Right.
So this can be a temporary variable.
Right now I will just go ahead and print okay.
So one print I will just use an F string.
And inside this f string let me first of all go ahead and display my student underscore ID okay.
And this will basically be my student underscore info.
Right now I may want a scenario wherein I traverse through or I iterate over all the elements that are
inside this.
Right.
So let me do that.
So I will go ahead and write for key comma value okay.
In student underscore info right I need to iterate through this.
And this all information are present inside student underscore info.
Now inside this also I will be able to find out keys and values.
So I will go ahead and print F again my key.
And this will be nothing but it will be colon again my value right now let's go ahead and see.
Uh so there is an error for key comma value in student underscore info dot items.
I, I missed out dot items because I am not getting too many information out of it.
So see how it is printing this first information.
This is my student.
All the information is over here.
Then I took this info and I iterated through every key and values.
Right?
So name is equal to crush.
Age is equal to 32.
Then again it went to the for loop.
It found out the another student ID that is student two with this name and now it is printing name is
equal to Peter and age is equal to five.
So this is how you iterate over nested dictionaries.
And you can play with different different elements as you want.
Okay.
So again Ellen any level of nesting let it be right.
You can iterate through each and everything.
And just by using dot items you can get the key value pairs.
Okay, now let me just go ahead and talk about dictionary comprehension.
Like how discussed about nested list uh list comprehension.
Similarly we'll discuss about uh dictionary comprehension okay.
Now dictionary comprehension.
How does it work.
Uh, and uh, let's say that I want to just print what is the square of a specific number between 1
to 10.
Okay.
So let me just go ahead and create a variable.
Squares is equal to.
And again what is the mechanism in list comprehension.
We basically write like this right.
In dictionary comprehension we use uh angular braces right.
So first thing first always remember we need to write.
You can write a for loop.
You can write any condition over here.
So let me go ahead and write for x in range of five okay.
So I'm iterating between 0 to 5 and what I want I want to display something like this x is equal to
x square okay I'm basically squaring each and every number.
And that is what is my x value.
And this way it will probably display me.
And this is the way how key and value pairs displays.
Right.
right?
So this is my key.
This will be the value.
This will be my key.
This will be the value as we keep on iterating.
So if I just go ahead and execute this print squares again you can one assignment I definitely like
to give you.
Just go ahead and write this entire thing with a simple for loop okay.
And then you try to convert this into a dictionary right a dictionary comprehension.
So here you can see now I'm able to get a key value pair.
So this is my zero is my key.
Zero is the value.
One is the key one is the value.
Two is the key, four is the value.
And we are doing the squaring of it right.
Squaring off each and every number.
Now let's say I want to probably go ahead and just find out the squares off only even number.
So here I will also show you by writing conditions.
So let me just go ahead and write conditional dictionary.
Comprehension.
Okay.
Comprehension.
Now the best way over here is that I will go ahead and create even variable.
Now first of all for x in range of ten let me just go ahead and take ten variables.
Okay I know what I need to display x square okay.
But I will write one more condition.
If if x modulus two is double equal to zero I will go ahead and print my events okay.
Now let me just go ahead and execute it.
So this is zero column zero two colon four four.
Column 16 six.
Colon 36 eight.
Colon 64.
Right.
So this is in short giving me the square of only even numbers.
Right now these are some of the examples.
Again dictionary comprehension.
You can like how do you execute with respect to list.
Similarly you can also do it with respect to uh ordinaries only.
The thing is that you need to have the output over here in the form of key value pairs.
Okay.
So this was one of the most amazing thing.
Okay.
Let me just show you some of the practical examples that may be beneficial for understanding, um,
some more practical examples.
And in the next video I will also talk about some of the amazing use cases where all this list, dictionaries
or dictionaries will be used.
Okay.
So practical examples okay.
Now with respect to this practical example I will give you a task.
Use a dictionary.
Okay.
Use a dictionary to count the frequency of elements in list okay.
Now we'll go ahead and see this.
Let's say I have numbers.
Numbers is nothing, but it is in the list format one comma two comma two.
comma, three comma, three comma, three comma, four comma four comma four comma four.
Okay.
So these are my numbers.
Now you need to write a code using dictionary to count the frequency of every element in the list.
Like one is present one time, two is present two times something like this.
So I will go ahead and create.
First of all you try it out.
Okay.
Just pause for five, five, at least five minutes and just try to write whatever is possible by you
and then go ahead and see the solution.
Okay.
Now let me just go ahead and create a frequency empty variable.
Then I will go ahead and write for number in numbers.
Okay.
First of all I will iterate through each and every number.
Then I will go ahead and write if number in frequency.
Okay.
If the number is basically present in the frequency, then it is fine.
Then what we do, we basically take that frequency of number and we keep on incrementing it.
Right.
Plus is equal to one.
Now what exactly this is basically doing this is with respect to the key and with respect to that particular
key I need to just increment keep on incrementing the value saying that hey it is present one time two
time three time Like when two times basically comes, right?
So first time it will be zero and then it will go to one, two, three like that okay.
Else if it is coming for the first time then we should basically assign that value to one, right.
Otherwise it will keep on incrementing.
So number is equal to one.
Now let me just go ahead and print the frequency.
So here you'll be able to understand how many number of times one is present, two is present and three
is present.
Just see this code.
Observe this code okay.
If I go ahead and execute it now here you can see numbers.
It is iterating.
If number is in the frequency initially it is not present.
So what it will do it will go over here.
Take this number and it will assign the value one.
Then it will go again back to the next number.
Two is present number is not present in the frequency.
It will again go back to the else loop.
And again it will update one.
Then again it will go back okay.
Then the next number is two.
This time it is present in the frequency.
So it will go inside.
This frequency of two is equal to plus is equal to one right plus equal to one.
So that basically we are just going to increment one with one.
So it will become two.
So how many number of times two is present.
Only that much will be remaining three.
It will increment till three four it will increment till four because there are four number of fours.
Okay.
okay.
So this is how you specifically get one amazing thing okay.
Now let me just show you another one example.
And this is probably we have not discussed.
Also let's go ahead and merge two dictionaries into one okay.
There may be scenario that I may have two dictionaries and I really want to merge them into one.
Okay.
This is one kind of hack that I really want to show it to you.
So dictionary one and this is what we will understand when we understand about functions, because there
is one very key important parameter which is called as positional argument and keyword argument.
Okay.
Uh, why we use Asterix mask and all.
I'll just discuss when we discuss about the function.
So now let me say that hey, there is my dictionary elements over here a is equal to one and this B
is nothing but equal to two okay.
Similarly I may have a different dictionary.
The second dictionary here B colon three and c is colon four.
Okay.
Now if I go ahead and write merge dictionary okay.
Now see if I go ahead and try to merge this dictionary.
I will use two amazing things over here.
One is asterisk.
Asterisk.
Dictionary one okay.
Comma asterisk asterisk dictionary two.
Now, the best thing about this asterisk is that any number of a number of key value pairs.
Right.
If I'm giving two double asterisk any number of key value pairs, that is probably going to consider
come.
It is just going to take that as a key value pair, and it is just going to append it inside this particular
dictionary okay.
This is basically called as a keyword argument okay.
And over here you can see in dictionary one and dictionary two both are keywords argument okay.
So keywords argument basically means any value that is present in the form of key value pairs.
Okay.
Now if I go ahead and print this merge dictionary and we'll discuss more about that in functions okay.
So here you can see that it has merged very much easily okay.
So I hope you got an idea about dictionaries.
We have discussed so many different lines of code I have written over here in front of you, and almost
each and every topics with some examples.
And all I have actually explained, explained in a way that you should be able to understand a very
lame language.
So I hope you like this particular video.
This was it for my side.
I will see you all in the next video.
Thank you.
Take care.