 Hello, my name is Samprit Patel, assistant professor, department of computer science and engineering, Walchand Institute of Technology, Sholapur. Today we are going to see a collection data type called dictionary. So this is one of the four collection data types present in python. In this lecture you will be able to understand the collection data type of dictionary and you will be able to apply dictionary in different applications. Now what is dictionary? Dictionary is made up of key and value pairs where the key and value are separated by a colon and the pairs are separated by commas. The key value pairs in all are enclosed in braces. In a dictionary the keys should be unique where the values cannot be duplicated. This dictionary or this data type is an immutable data type. Now creating a dictionary. To create a dictionary we can use the dictionary name equal to and assign the keys and values enclosed in curly braces. As said before keys and values are separated by a colon and the pairs are separated by comma. So we will see an example. So this is a dictionary declared as this dict which has assigned three key value pairs that is school, has children, college, has students and company has employees. So we will run this code. So in this manner the dictionary has been printed. So it will define that a school key will have its value as children, college will have a value as students and company will have value as employees. So moving forward how to update a dictionary. So if you want to update any value to a key in a dictionary then we can use the following syntax. Dictionary name in square brackets you have to specify the key of which the value has been updated is equal to you have to assign a new value to that key. This is one way you can update the dictionary. The second way to update a dictionary is using the update function. So dictionary name dot update in brackets enclosed in braces key value. So we will just check it out. So we will update company. So say this dict update in this bracket we have to first specify key as company. So it should be enclosed in single code which will be separated by colon and its value will be workers. Now we will print. So see the company employees is been replaced by company worker. In this way you can update the existing key to its new value. You can also try this example that name in square brackets you have to specify a key. So we will again change that company workers to company employee. So this dict into square brackets we have to specify the key. The key is company which is equals to we have to assign a value as employee again. So print this dict that is the name of the dictionary. So the company should be enclosed in single code as it is a key. So you will find an error if you don't specify any string value in a single code or a double code. So see again the company value is changed to employees. The next part is deleting an element from a dictionary. To delete an element we can use DEL keyword followed by the dictionary name and the key which specifies the element. So we will try this is equals to this dict and we have to specify what we have to specify the key and not the value of the element using square brackets and single codes. Now we will delete school. So s is capital you also need to take care of each and every character. So you have to print it to get a display. So print this dict. Now you will find in the fourth line of the output that the school and its value children is been deleted from the dictionary. Now second syntax that is clear will delete all the elements in the dictionary. You can try it as we require the dictionary for further examples. Now properties of the keys. So there are two important properties of the keys that one entry per key is allowed. There should not be any more entries per key. So if there is school school will have only one entry and not multiple entries and keys must be immutable. So you cannot change the keys or update the keys. You can update the values of the keys. Take your time and write a program to script at the key to a dictionary. So this is the answer. Now we have seen to add a key to a dictionary we have to use update function. So dictionary name dot update into bracket in curly braces you have to specify the new key and its new value. So this will add a new key and value to the existing dictionary. Now there are some building functions for dictionary. The first function is to compare two dictionary whose syntax is cmp into brackets. You have to pass the both the dictionaries you have to compare. Then to find the length of the dictionary you have to use alien function to produce a printable string representation of a dictionary. You can use string function passing the dictionary name as a parameter. If you want to find out the type then just use type function as a parameter you have to give the dictionary name. It will return you the type of the past variable. If the past variable is a dictionary then it would return you a dictionary type. Now apart from built in functions there are some methods which will help you to manipulate dictionary. The first method is clear which will remove all the elements of the dictionary. Second is copy which will return a shallow copy of a dictionary. The third is from keys. This will create a new dictionary with keys from sequence and values set to value. Dictionary get the get function is used to return value or default if key not in a dictionary. So to find whether the key is present in the dictionary or not we can use get function. Similarly whether the key is present in a dictionary or not you can also use has underscore key function. If this will return true or false dot items function will return a list of dictionary key value double pair dictionary dot keys will return the keys of the dictionary. Set default function is similar to get but it will set a dictionary key as default if the key is not already in dictionary. So it will only set it to default if it is not available in the dictionary. The last two are update which we have seen and dictionary dot values will return you the values of the dictionary. I hope you have understood the collection data types in the previous all four videos. These are some references I have used to create this PPTN video programming in python 3 of PSN publications and core python programming of dream tech press. These are two books or reference books apart from this I have been using w3schools.com a website to get some information and resources regarding python. Thank you.