0:00
Hello everyone, welcome to chapter 9 that is Dictionaries. I will be explaining the dictionary data types in detail
0:06
So basically to represent a group of object as a key value pair we are using dictionaries
0:12
So for example, you have you must have seen the phone book dictionaries
0:17
Variant there is a name and then we have phone numbers, right? So
0:24
Similar way, these are the key colon value pairs which are inside opening and closing
0:31
curly braces We called it as dictionaries here duplicate keys are not allowed but values can be duplicate for example
0:40
I have a dictionary one Wherein the value is one Sorry key is one with the value of one
0:49
comma two has value of two comma three value of three so now I cannot use one more key with the same value of one with
1:03
Different values right? Basically I can use this value Again, the values can be duplicated in another key value pair, but key cannot be repeated again in a dictionary, right
1:15
So it will me instead of one I should do four and but I can use this to twice
1:20
So that is how we are allowed to have a different Duplicate values but not the keys heterogeneous object are allowed just like how I have seen like digits and strings or characters
1:35
Together that insertion order is not preserved here also just like seat
1:40
We cannot do indexing and slicing but instead of that whenever you wanted to call something you just have to call
1:47
Its key instead of its index Dictionaries are mutable dynamic and indexing and slicing is not applicable
1:56
Mutable means from outside you can just do All of the other values
2:03
assignments to the dictionaries by Just giving its any value to the
2:08
Key, so in C++ and Java dictionaries are also known as maps whereas in Perl and Ruby it is known as hash
2:15
So these are the dictionary in Python This is one of the most important topic that is discussed inside your interview now how to create them similar way
2:24
We have seen in sets. This is a definition of dictionary now
2:28
for example You are just adding the values how to add values first one is D of 100 that is key with value of Python
2:38
So this is an example one so now D of similar same dictionary with another value of 10 having value is or
2:47
Same dictionary with value Easy add key 200. So whenever I am printing all
2:55
Dictionary D. I can have 100 Python 10 is 200 easy So 100 Python 10 is 200 easy this will be outputted similar way for example opening and closing
3:06
Opening and closing bracket inside that directly I can write key value pairs by comma separated
3:12
I am printing dictionaries of stuff 200 means this particular keys value will be a printed
3:19
D of 200 means this particular dictionaries key value will be printed. So this is one dictionary
3:25
This is another edition this way We can define and call the dictionaries now how to delete the elements from dictionary. You just can use DL
3:34
keyword with dictionary of 200 So this case value will be deleted from the dictionary C
3:40
So this key value pair is 200 is right? So 200 is complete key value pair is deleted from the dictionary
3:48
second one will be to remove all entries we can use clear method and
3:53
similar way if at all Total element or total dictionary you wanted to delete you can just use delete and dictionary name here
4:02
We were talking about Dictionaries key, but here we are talking about complete dictionary
4:07
Now when you try to print the dictionary, you will get an error saying dictionary is not defined because you have a dictionary
4:13
This is a definition that we have seen this way dictionaries are created now to update the dictionaries
4:19
But we have seen directly by changing the key and its value
4:24
We can update it for examples. I am now for example, I wanted to add one more key value pair
4:30
Just you have to see for this key what is the value and it will be added
4:34
Similar with another value. So now instead of three key value pairs, we will have five key value pairs to delete
4:41
We have seen completely dictionary will be deleted and here only one of the element will be deleted now
4:48
To remove all entries clear is something which will clear out the dictionary and empty dictionary will be there
4:56
Not to delete yes new different between clear and Delete is that it will still be there as an empty dictionary, but here the location it will not be there inside your memory
5:08
That's why the dictionary will not be defined this name error will be there
5:12
So now what are the different functions just like we have seen in list strings tuples
5:17
And sets so one of the function is length It will tell the number of items in the dictionary items is nothing but key value pair
5:25
So one key value pair is one item similar way to remove all elements. We have used this particular
5:32
Clear method now to print one of the key value pair or to get the values
5:37
We have seen by just telling what is a key your value will be there
5:41
Another method is you can use get and put the method as well
5:46
Whenever I am seeing get of hundred means Python will be printed similar way if at all I wanted to pop
5:52
The element inside list it was popping out last element inside set it was randomly popping out
5:59
But inside dictionary you have to tell the key which you need to delete right and then the last one will be
6:06
Pop items, so it will completely pop out any random key value from the dictionary, right
6:15
so after that there is a one more Way to access the key values of the dictionary by using for loop you can see
6:24
Because we know inside items we have keys and values, right? So keys will be there and values will be there. So
6:32
Let me go back to our PowerPoint presentation for example We have a different keys right with values as one
6:44
to Value as three three values as a four for example, this is our dictionary now
6:51
We have all key value pairs. What are different keys one two three
6:56
What are different values one three and four so we can apply for loop on key separately
7:02
We can apply for loop on values as well. So that's like to access I am doing for I comma C in
7:09
dictionary dot items Right, but this is the way we are just accessing I and B you can do give any name to this elements
7:20
But this is something I am using I come away in dictionary dot items
7:24
Print I print V see so all these elements separately will be printed right? So I'm just spending about
7:33
keys and values since it has only single values left and Then similar way we can copy the dictionary just like we have copied the sets and to update the dictionary
7:44
We can create one of the empty dictionary and dictionary three dot update similar way
7:50
Extend was there. So we have to update this study one That means on the image from dictionary one will be there to dictionary three so that will be combined together
7:58
So that is it From the dictionaries we will see in the next chapter. Thank you