DICTIONARIES(ADDITION,MODIFY&DELETE) - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous session we have seen the introduction to dictionary concept and how to create a dictionary and how to access the elements from the dictionary so here a dictionary is a key value P so that the keys are nothing but attributes and the values are the corresponding to the keys and here how to access the dictionary so we can access the elements of a dictionary with the help of keys so let us see this one so dictionary in SiC key value P so we have to write the multiple elements that makes a multiple key value base separated with a comma and closed in a curly braces so key : and we have to represent this key value pay with the help of a colon operator so key kourin corresponding value so key one valuable comma key to value to come home and so on so this is the representation of a dictionary so example let us take an example some name ABC some are number 20 so let us take only two elements so these are called elements and these two are the keys and these two are the values so how can I access all these elements so this is how we can create a dictionary so this is how we can create a dictionary and how to access the elements we have to access the elements with the help of jeez so instead of using the indexes here you use the keys so if you accessed the with the help of the key the corresponding value will be read to right now include accession we'll see a few concepts as simple concepts that is adding new element to the dictionary modifying the existing element deleting an arrangement so we've considered one dictionary then we will see how to add a one more element that was a new key value bail into the dictionary and how to modify the existing element so already we are having a few key value pairs we will consider some example so how to modify and deleting how to delete the elements so how to delete a single element and how to delete multiple elements or how to clear all the elements right so one of my goals we'll see and then we go with the implementation part so I will show you how to create how to access and how to add modify and delete in the Python interpreter alright so first one is a D let us take an example some D is equal to so let us take name ABC number 3 branch 6 so here we have having a dictionary with the three key value page one is a main number and branch so here the keys are name number and a branch values are ABC 23 CS now how to add a new element so in order to add a new element simply we can write the syntax as d off so the dictionary of the key is equal to value so these are the new key value pair so these are the new key value pay so we can write if you want to add one more element into this dictionary you can simply write it as d of course is equal to b take so if you add this one so this is a new one so of course is not there in the existing keys and reading is not there in the existing values so if you write this one and after print this one so you get all these elements including the new thing course so simply by using an assignment operator we can add an element into the dictionary right so once again I am repeating that here instead of using the index values here we will use the keys okay in order to access the elements or adding the elements or deleting the elements or modifying elements we'll use the keys so the corresponding values will be modified on a break it right so this is how we can add an element a new element a new key value pay into the dictionary now let us see how to modify so how to modify simply so in order to modify also we have to use the existing key and that will be done with the help of assignment operator so so existing key is equal to new value existing key is equal to new value see if you lose here in the other example so in the error example we are having some four keys name number branch and cooks so I have want to update this close right then simply do of course is equal to pick and pick then if you print this one if you print this be simply the course value will be updated so for everything we have to use the keys okay then deleting the elements deletion so how to delete so here also we can use diesel method at the yield keyword and clear function DL keyword and a clear function so first let us see the DL keyword so if you want to delete any one element or any one key value pay from the dictionary we can use this delete D so this is used to delete one or more elements and this will delete tips all the elements right so the syntax for this one is de el key word for word by dictionary give the key so that that will be deleted that element will be deleted that term right or simply so this will be the given keeping and deal dact it will remove the dictionary from memory so that means everything will be deleted it removes that externally from the memory digital digital so here we are not specifying any keys so it will delete everything similarly the AICP dot clear function it will clears all clippings all key value pairs from dictionary so three ways we can read an element from the distant so one is DL keyword so DN followed by the dictionary we have to specify the key right so instead of using the index we have to specify the key so that that corresponding key pay will be deleted and Deanna dictionary it removes the dictionary from the memory itself so the complete everything related to the dictionary will be deleted and Dictionary dot tail function it will create tears all the key value pairs from the distant right so hope you understood this one and now we will see the implementation of everything in Python interpreter so we will see how to create a dictionary and we will see how to access the elements of the dictionary and we will see how to add how to modify and how to do it all these things so DL keyword and a clear function so that your doubts will be clarified right now we will see the implementation part of the dictionary concept so first we will create a dictionary so we know that the dictionary is a collection of key-value things right which are enclosed in between the curly braces separated with a comma C so d is equal to the curly braces open you have to write the keys so name and we have to specify the key value pair with the help of this column operator so key colon value we have to write the value separated with a comma multiple elements will be separated with a comma so our number : 23 branch CSE so this is how we can create a dictionary so now a dictionary is created with three key value page so that is a name our number and a branch suddenly now if you print this D you can get all these things okay so now so this is how we can create a dictionary and who can access the elements with these key value page so in the previous concepts that means if you consider that list concept so we will access the elements of a list with the help of a index here we'll access the elements of a dictionary with the help of keys so similarly the same the syntax is same but instead of using the index we'll use the keys so if you access the named Saudi of print D of you have to give the name then automatically that particular value will be I turn that particular value the corresponding value will be printed similarly print of D of our number so we can't access the keys with the help of values okay we can access the element only with the help of keys so here the keys our name our number and a branch see I will show you so if you access this one so it will consider as a key and it will return an error okay key error because here ABC we know that ABC is a value but interpreter will consider this yes a key which is not available in this dictionary so it returns a key error so this is how we can create and access the dictionary elements and if you add one more element in the dictionary so that is also with the help of this one what is the syntax the dictionary followed by the new key is equal to new value by using the assignment operator we can add more elements into the distant so just I will add one more element so D of course is equal to B Tech right so already course is not available in the dictionary horses are not available in the dictionary so we are now adding that course into the dictionary concept so if you print D will get a four elements name RNA but branch and course and one more thing we have to remember that the keys should be identical the case should not have any duplicates so see if you give a duplicate key so d Oh see here this is a way how can we add the elements okay now we will modify and later we will see their duplications right so just will modify an element so that is also done with the help of the assignment operator all right so the syntax is same D give the existing thing course is equal to empty so this will override the value of the course key so if you print this one you can get the new details for the course so if you observe here so here we have created an key value key value pair as a course booted and in the next thing we have just again assigning a mtech as a value for the same course so it will be overriding so no duplicates will be allowed here no duplicates will be hello right now we will see the deletion how to delete so deletion can be done with the two functions one is a delete operator de el keyword and the clear function so if you use a de el we have to specify the key right de el followed by dictionary of specify the key so it will delete one element okay it will delete one element see if you print D so here we can get only three key value page because we have related the fourth one next we will assign this dictionary to one more thing so a is equal to D so now all the elements so by using the simple assignment operators we can use we can assign the complete dictionary rule one more variable so now I am assigning the variables I mean the elements of D 2 element 2 a now a is also a dictionary with the same elements right now let us use a DL command ye l d so it will remove the dictionary from the memory now if you print this d will get another name b is not defined because d is deleted from the memory not and not it will it not clears the elements but it will delete completely from the memory right so we are having one more dictionary a so here we will use a dot clear it out clear so this will clear element from the dictionary but not from the memory so if you print here we will get an empty dictionary you will get then empty dictionary so in the previous case if you use a de L followed by the dictionary name it will delete the complete dictionary from the memory so we will get an error called a name error that D is not defined and also there is one more method that is there so there is a pop we have to specify the key in the pump okay so let us create a dictionary with a duplicate names so that you will understood some name ABC for number 23 some are number 34 see what we have observe so in in the creation we are giving name as a key and our number as a key and in the name we are specifying ABC and in the are number we are giving the two values one is the 23 a another one is the another one is a 34 so their last assigned value will be assigned to the key so here first we have assigned to 23 and next we have assigned 34 so only 34 will be overriding to the 23 so not both so here the one thing we have to remember is the keys are identical so that means a there must be no duplicates in key key should not be repeated and the last recently assigned value will be available in that particular key right so hope you understood this one so if you are having any doubts regarding this dictionary concept feel free to post your doubts in the comment section so that definitely we will try to clarify all your doubts and in the next session will go with the methods available in the dictionary there is a very important and there we can see the implementation part also right so follow our channel and if you really understood my sessions like my sessions say my sessions with your friends and don't forget to subscribe to our channel thanks for watching thank you very much you
Info
Channel: Sundeep Saradhi Kanthety
Views: 14,969
Rating: 4.9507694 out of 5
Keywords: SUNDEEP, SARADHI, KANTHETY, PYTHON, PROGRAMMING, HIGH-LEVEL, LANGUAGE, INTERPRETER, PYTHON SHELL, PYTHON SCRIPT, INTRODUCTION, BEGINNERS, tuples, tuple, Learn Python, Python Programming, Python Language, Python Tutorial, tuples in python, accessing elements, Python Basics, mutable, immutable, paranthesis, dictionaries, keys, values, items, mapping, dictionary comprehenion, accessing dictionary, dictionary creation, dictionary methods, addition, modifying, deletion, clear, del, insert
Id: FW7esDscxSA
Channel Id: undefined
Length: 22min 43sec (1363 seconds)
Published: Tue Aug 27 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.