In this situation, we are discussing Python Dictionary, so what is the Python dictionary and how to
define that one?
What are the different methods we can apply on this Python dictionary?
We'll be discussing that, run into details.
In Python Dictionary is an unordered collection of items, while other compound types have only value
as an element.
A dictionary has a key value pairs, so that is a very important one.
So we had a discussion on leaves.
We had a discussion on table.
We had a discussion on set that is so that we are having multiple different elements.
Are there they may be or may not be of the same or different data types, but here we are finding this
dictionary is quite different from those those data types, because here in the dictionary we are having
the key value pair dictionaries are optimized to retrieve values when the key is known.
So if you know the key, if you pass the key as argument, we can retrieve that respective value against
the key which has been stored, stored onto the dictionary object.
So here you are considered one that is a my dict one.
So this is a variable which is containing one colon red.
So what is one that is a key.
What is the value that is read.
Is read is a string.
Yes.
So it should be enclosed within single codes.
And here this key value pair must be separated by this colon then come up.
So we are having the second member, having the third member and so on.
And each and every member is nothing but key value pair.
So we are having this Maidique two.
So here we are having this name.
So there is one member here.
So so H Colon thirty five addressed colon in this way that things have got represented.
So here you are having the different methods which you can carry out on a dictionary.
So the first one is a clear remove all items from the dictionary copy, return a copy of the dictionary,
then from keys.
So sequence within third decade, we're putting this come up.
So return a new dictionary with keys from the sequence and the value equal to be default to none here.
So in this way you are also having the get key within the third week we're having B here.
So return the value of key.
If the key does not exist except then return D and default is to none.
So in this way we are getting this one.
So let's consider this one as exist.
So now this is my items so written in new view of the dictionaries items, that is a key and value.
So these are the different methods are there and the respective descriptions we have given.
You can go to them because actually are having a plan to show you all these methods, which are very
much useful in our in our python programming, in our life demonstration there.
So let us go for the demonstration, for the better understanding that how this method going can be
used on our dictionary objects and what are the results we are getting.
So here is a demonstration for you.
Python Dictionary is an unordered collection of items, and while other compound types have only the
value as an element, but in case of dictionary, it will be having our key loopier and dictionaries
are optimized to the values when the key is known to us.
So let us go for one creation of a of a dictionary here.
So new dict is equal to one colon.
So here one is the key and values the value.
And you say colon is the respective separator between the key.
And so these key envelopes would be separated by this comma and the whole thing must be enclosed within,
Culebra says, as if it is a set Inca's upset.
Also, we had all the set elements are to be enclosed within Culebras, but here in this upset, we
only have the elements here, members there.
But here in the dictionary will be having our key value pair.
So print Newdegate.
So now they can go for the execution.
You can find that we're just printing this this particular dictionary and then print Newdegate.
So this outcome has some print Newdegate one.
So we are given one means a key value.
So here we are having the skite.
So the respective value will be so has got printed.
If you go for this get and if you get two, then two is the key here and the value will be high.
So high has got printed.
So now you might be asking me what is the difference between this new DECT one and Newdegate get to
here.
The difference is that if you keep some if you keep some illegal or non-existent key here, so 10 is
not there at present.
So if hagwon execution, then I can find that key error is coming.
So here is the key.
The value, whatever we are giving it, the respective key is not existent here.
We are getting one error that is accurate.
Key error 10.
So that is that issue.
But in this case, if I put one in key here.
So here you can find that it is returning none.
It is returning none.
So that is a basic difference between these two respective statements that is printed new one and print
Newdegate get.
So if we give, Dufka says, the valid key in that case, I'm getting this Halleran high, as I explained,
updating Peloso for the new dict one I'm putting here.
So now we see for this one, for this against this key, the value has got updated from hello to here.
So now we are having this adding value.
So that is a new dict for is the amnesty.
Now here you can find that here Dysport is not existing here.
So a new respective people loopier will be inserted in this dictionary.
Now creating a new dictionary.
So let me go for the executions of green squares, their respective values are getting printed.
So now remove a particular item.
So we are going for squares DOT four.
So as of key is given directly for four.
So that means for on 16, this particular this key value will be deleted.
And that's why you it is returning the value at first 16.
And you can find that, that for colon 16 that gives loopier is missing.
Now remove an arbitrary item.
You can go for this item.
So in this case, a pop item, one arbitrary item will be deleted.
So here you can find that five Gomaa 25, it has got deleted.
So the respective value is not is now not existing.
Delete a particular item.
We can go for this deal and in square one.
So this particular key value will be deleted.
So we are remaining with this two column four and three colon nine here.
Here we have defined one new dictionary, there's a square, so squares have got printed.
Now we are going for these squares to clear.
So it removes all the all the developers.
So remove old items.
And now if you print this square, it is printing that empty dictionary.
So delete the dictionary itself.
In that case, if in that case will be going Fadell Square.
But after that, if you want to print squares as the squares have got deleted, so it will produce one
error that is a nimura.
So there is a numeric.
So name squares is not defined because we have used this deal here.
So that full declaration of the dictionary itself will get deleted.
Next one, creating a new dictionary, using comprehension so we can find that X in range six, that
means X will be ranging from zero to five because X will be exclusive.
So zero, one, two, three, four, five.
So these are the six values for X.
So we are creating a dictionary that is Escalon.
X will be the key and the value will be XRX.
So now in this case, if I bring the squares, I'm getting the zero zero square and then one one squared
and then two is the key and the value will be two square three is the key.
There will be three square in the square, up to five colon twenty five.
So we are getting this.
So dictionary membership test.
So how to do the membership test here.
So here in this case we discuss only the dictionary using comprehension.
Now it is a and here you'll be going for the testing of the membership.
So one dictionary has got a defined so name of the dictionary is square.
So now one in square.
So one this key is present.
So one in squares will be giving us.
True, because we are testing the membership of this one as a key in this dictionary.
Do not in square.
You see the two is not there.
So two not in square will produce the outcome through here, but print at 49 in square 49 as a key is
not present here.
So that's why it is returning the value.
It is returning the boolean value.
That is false.
So here, whatever you are passing, whatever you were mentioning, they are the key that we are not
considering.
This 49, which is present as a value as a key 49, is absent.
So print 49 in squares, it is returning.
The value falls.
Now we are going for this iterating through a dictionary, so square one on one three nine five point
twenty five, we define this one.
So for I in squares, so print squares, I so you can go for the execution.
You can find that we are printing this one nine, 25, 14.
And so they are all the values.
So here this guy has been treated as a key, so respected value has been popped out and has been retrieved
and they have got printed in this iteration.
So we are finding out there is there is a square is one dictionary here.
We're going to the.
So these are the inbuilt functions in a dictionary.
So Lin will print the length of the dictionary.
That means that a number of key value pairs.
So here you are printing this one is five because one, two, three, four, five key value pairs of
their print chocolate squares.
So you can find that the respective key values, they have become sorted.
They have become sorted here.
So in this way, we are having some inbuilt methods that are inbuilt functions, that they are building
functions, that they are in a dictionary that can be applied on the dictionary objects.
So in this discussion, we have a detailed discussion that how to create a dictionary and what are the
different permitted and not permitted operations that we can carry out on a dictionary?
I think now the conception is getting clear to you.
Thanks for watching this video.