DICTIONARIES (CREATION AND ACCESSING) - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so today's session we'll see the concept of dictionary in Python programming so in the previous sessions we have seen the sequential data structures like list set tuples right so we have seen list so tuple and set so these we call it as a sequences sequences because it consists of a multiple elements so here the dictionary is also consists of multiple elements but in terms of key value P in terms of key value P so the case both the key in value will be forming in pain and this will be considered as a single element in dictionary so we should call it that you should not call it as a sequence so this is called as mappings rather than sequences so we should call it as an mappings rather than sequences so we should not call these as a sequences so so here also a key value pain and this can be of any data type let us see group of key value pairs separated with comma and enclosed in curly braces right this is the word curly brackets service list we enclose the multiple elements which are separated with the Karma him square braces tuple will give us appearances in a set again we are using curly braces and in the dictionary similar to the set it will also the inverse of a dictionary will also be enclosed in curly braces but in terms of key value P key value P right so this is the definition simple definition we can say about this dictionary right so let us create dictionary is equal to curly braces so here we have to give a key followed by the value right so let us take an example name name is a key and this key value pay this key value P are separated with : is key when you fail is separated with Corin name some a b c comma so this is all one element right this complete page will be considered as a one element so left hand side to this column will be ticket as it is right Hansen is treated as a values so this forms a key value P for number I roll number comma Department this so here the dictionary fences off a key value believes separated with a comma separated with a comma and closed in a square bracket so this is a key this is it hope you understood this one this is a key this is a value right so we are having three elements so here we call these as items in terms of dictionary ah I think word name ABC so fond suitable okay come on our number subtitle PT secrecy right so these are the items offer dictionary so we should not call them call these as elements we'll call these as items so why items means there is a function called items so there is a method called items which will display all the elements of the dish name so we can treat these elements as a items so that we can easily implement that thing okay now so how do create a dictionary right so we will see how to create a dictionary so how to create a dictionary so an empty dictionary is created as so this is an event additionally some BACT is equal to open curly brace close curly brace so this is how we can create an empty dictionary now so how to create a dictionary with elements dictionary with items so for that we have seams so di CT is equal to open curly brace so we can go with the key colon value so you read the syntax here so keep : value 1 comma 2 so this is the syntax for creating a dictionary with the multiple key value pins and if you want to write it in a single you know I mean in multiple lives we can also write it as B AC T is equal to so write the statement key I mean right all the pace is individualize okay : value to key 3 corner so in similar way also we can create a dictionary so writing the key value paid you singing life every key value been missing right so this key value be any debt attack if it is a sting we have to enclose that string in between the single quotes or double quotes so that's the common procedure so and this is how we can create a dictionary and also we can create a dictionary by using the dictionary function this is a titles this is an empty dictionary next dictionary function so there is a function called dact which is used to convert into the dictionary it forms a key value pairs so we can use this dictionary function to create a dictionary so we will see how it will be created dictionary function so here we have to give a pane of key values in tuple C pencil dact of even karma value1 he do common value to and so on so in such a way we help to give the key value base so this function will create a dictionary this value will create a dictionary with the givers index so value one come on so it falls it okay thank so directly we can so we can create a dictionary and until dictionary and we can create a dictionary where you specifying the key value pairs in a curly braces in a single line and we can create a dictionary with specifying the multiple elements and specifying each element in a single line and also with the help of this dictionary function and next we can also create a dictionary using comprehension so we have seen this list comprehension so based upon the expression the dictionary will be created so we have to specify an expression iteration condition so we have to follow the same order so dictionary is equal to expression space followed by iteration space followed by condition so this is the syntax for creating the dictionary with the use of lists in dictionary comprehension for example let me explain it with an example so X pace with so this is the key value base so we have to specify the key and a column and then so X star to full but for X in range 5 and here this condition is an optional here the condition is an optional so we can use or we may not use so let us take if X mod 2 is equal to is equal to 0 so this implies we have to give the XP for all the values of X in between 0 to 4 which are which are nothing but which Lord 2 is not equal to 0 means simply if you feel zero in front of a comma to confirm they pay for and finally for informs a page 16 so people give a result as this one so X : X double star - double star is nothing but our exponent operator so it will be treated as an X square so 0 0 square 0 - 2 squared 4 4 4 8 16 so because here we are giving the condition X about 2 is equal to is equal to 0 that means whatever the elements which are more treated as true is equal to is equal to 0 so first the iterations will be executed and based upon the condition this will be inserted into the dictionary so this is called the dictionary comprehension so by creating a dictionary we can specify the condition and based upon the condition we can create an element's into the dictionary right so if you are not specifying this condition so here the condition is optional if you have not specifying this one so then the result will be 0 0 1 1 2 4 3 9 4 16 so this is the result for this comprehension so first of always the iterative statements will be executed then based upon the condition if you are writing any condition that condition will be verified and if the condition is true then only the page will be formed and it will be created in the dictionary so this is how the dictionary comprehension will be working so with the help of digital confidence also we can create additional right so hope you understood this creation how to create a dictionary now accessing how to access the elements or items of a dictionary so coming to this previous sequences like lists tuples offset so with the help of index values will access the elements so here we are having keys and values a pail of elements we will be considering as a single item or single element so we can access the values of a dictionary with the help of keys so here there is a low concept of index values right so here we are having the keys in values so by using with the help of keys we are going to access their corresponding values so with the help of keys we can access transporting values like so we can see that mr. is equal to name a b c d bt c AC so there are three key value pics okay so this dictionary forms the three key value pairs if you want to access these values that can be done with the help of the corresponding keys so the ICT oh and here also we use the square braces for accessing the elements so in this way this is instead of writing this index values here will read the keys so dictionary of name similarly dact of bep d so this is string so we have to enclose in squib a currently no collisions dictionary of odd number so this will return ABC as a result and this will return CSC as a result and this will return our number as a result okay so this is how we can access the elements of a dictionary so this with the help of the keys so all these are the keys okay so all these are the keys that will the left-hand side which we are writing to the column those will be considered as a keys and right hand side are the corresponding values so with the help of key names we'll get the values of that corresponding keys and also there are the three methods so which we are going to see in the further sessions so items is one of one method items is one electorate which will return all the elements all the key value piece key menu please it will return it will display all the key value base of the dictionary and values it will return all the values of dictionary all the values of dictionaries similarly there is a method called keys it will return all the case of the dictionary so these methods we will see in the further sessions so this way I am saying for the destined and for an idea so there are different methods like this to access all the elements at a time from the dictionary so high terms values and keys right so this is how we can access the elements or items from the dictionary so I hope you understood these sessions so let us stop here in the next session we'll go with the modifications or updations and then different methods available in the dictionary so in the next session I will show you the practical implementation of this dictionary concept by implementing in the interpreter right so if you are having any doubts regarding this dictionary concept feel free to post your thoughts in the comment section so definitely we will try to clarify all your nerves and if you really understood my session like my session share my sessions with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 33,164
Rating: 4.9331617 out of 5
Keywords: SUNDEEP, SARADHI, KANTHETY, PYTHON, PROGRAMMING, HIGH-LEVEL, LANGUAGE, PORTABLE, FEATURES, APPLICATIONS, INSTALLATION, 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
Id: 4Q0pW8XBOkc
Channel Id: undefined
Length: 20min 53sec (1253 seconds)
Published: Fri Aug 23 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.