Okay, so welcome to the Python session. So in this video, I'll be talking about few functions, which you can use it dictionaries. So the first function that I use today is copy. So just write copy here. And let me create one dictionary. So I'll give a name original to my dictionary and then create a dictionary with like this, where one will contain a value one.
Two will contain a value to three will contain a value three. So let me create three keys with three values. So I've created it and I'll print it. Okay, now I will copy this dictionary To one new one. So I'll write new underscore one equal to or regional dot copy, user first bracket, if I use this, so all the values of this original dictionary will be copied to the new dictionary a new one. So run it.
Now print new one. See, the same values are copied to new one. So there is another way of copying but is a bit different. So new one we have created. And now I'll write new two equal to origin without using any any function and just write new to equal to origin. Run perfectly.
So print new to now and see the values See between the same values of origin now there is a slight difference of copying using the copy function and just exactly equal to operator. Now I'll show you one thing now if you want to clear the values of the dictionary new one, then you will write new dot clear user first bracket and run it. See give me error because I've written something wrong. That is it is under new underscore one and here I've written new one, so don't poke me. So now new one. Now print this new one and see what it will return.
So it returned a blank dictionary. Now if you want to check the value of the original dictionary See it has all the values 123. Now, if I clear all the values of new two which I have created using the equal to operator What happened? Just see new two dots dot clear. Within this first bracket, enter, now print new to it returned a blank dictionary, now print origin It will also return a blank dictionary. That is if you copy using our equal to operator then if you delete or if you clear any item of a dictionary, then the effect will be on the both dictionary So, both the dictionary values will be cleared will be deleted.
But if you use this copy function, then only that particular dictionary will be modified when you will use this clear function, but the origin will remain same. so this is the basic difference of copying our value of a dictionary by using a copy function and using an equal to operator. So the next function that we'll be using is from keys. So this from key method, create a new dictionary from the given sequence of element with a value provided by the user. So let's do it then you can understand. So first I'll create keys of a dictionary.
So without giving any value to that keys, and create just the keys of the dictionary, so keys equal to within this curly braces right? a div comadre be give a comma right see in this way on writing or without writing etc, we can just write the vowels A e, i, o, right? You so these are the vowels five vowels. So now, without running it come the next line, right vowels equal to dict dot from keys then within first bracket, write, keys and then print valid So, what I'm doing here is I'm creating keys first, then here I am writing vowels dict dot from keys, this from keys will create a sequence of create a new dictionary from the given sequence of keys, this even sequence of element so it will create this sequence of element and converted the dictionary keys, and then it will print those vowels.
See, these are the keys is now created from keys. Now, as I haven't mentioned, any value of that particular keys, so it is displayed as none. Now I want to incorporate the values of each key. So I write for satellite the keys again. So keys equal to the same way, I'll just write it EU you Okay, now come in the next line without running it right? values.
No hear you right I want to write vowels Okay. Then come in the next line. Now after define this vowels because this is my dictionary so take dot from kiss. Then within this first bracket you have to now write keys comma values. So to take it as a key and then the value vowel as the value of each key. Now, print vowels see what happened see Got it.
Each key has now the value vowels. So in this way, you can first create keys and then incorporate the values to it. Now we can also incorporate least in place of this values of a key. So if you want to store list within this key, then what you can do is suppose and to create lists, so I just copy this key from here, and then I'll write values equal to how we can create lists with the square brackets. So square bracket and write one comma two, comma three, these are the three values I want to store in this keys. So coming the next line, right vowels equal to dict dot From keys and write keys, comma, values.
Now print valance. See now in place of this values I have written least I've saved least in place of this value. So now each key contents at least in this way, so the next thing that we'll do is so now I just copied this two thing that is keys and values. Now what I'll do is I'll run this two things. So I've run it. And now what I will do is in the next line, I am right vowels is equal to within this curly braces key, then colon, then list then values and then port key in keys.
So run this and see what happened. It's done. Now. Print valance see, it has created the same list. So in this way also you can create your list. So this key method that is for key in case it will store the keys value that is this value in key, and the list in the place of values of that key.
So in this way, these are the few way in which we can create using few functions a dictionary. So these are the few methods that we have used to create a dictionary to copy a dictionary to modify a dictionary. So keep practicing. See you in the next video. Thank you