Hello Everyone! Today in this video I am going to show you some examples of split method and we are going to continue with our new topic Dictionary in which we learn about Creating dictionary, Accessing Items, Change Values, Loop Through a Dictionary, in and not in Operators: Check in Dictionary, Dictionary Length, Adding Items, Removing Items, Copy a Dictionary, Nested Dictionaries, The dict() Constructor & Dictionary Methods.
✻ I really hope you find this video useful.
Dictionaries :
A dictionary is a collection which is unordered, changeable and indexed.
In Python dictionaries are written with curly brackets {}, and they have keys and values.
Each element in a dictionary has two parts: a key and a value. You use a key to locate a specific value.
Accessing Items :
You can access the items of a dictionary by referring to its key name, inside square brackets.
There is also a method called get() that will give you the same result.
Change Values :
You can change the value of a specific item by referring to its key name.
Loop Through a Dictionary :
You can loop through a dictionary by using a for loop.
When looping through a dictionary, the return value are the keys of the dictionary, but there are methods to return the values as well.
You can use the for loop in the following general format to iterate over all the keys in a dictionary:
for var in dictionary :
statement
statement
etc.
In the general format, var is the name of a variable and dictionary is the name of a dictionary.
in and not in Operators: Check if Key Exists
To determine if a specified key is present in a dictionary use the in keyword.
String comparisons with the in and not in operators are case sensitive.
Dictionary Length :
To determine how many items (key-value pairs) a dictionary has, use the len() function.
Adding Items :
Adding an item to the dictionary is done by using a new index key and assigning a value to it.
You cannot have duplicate keys in a dictionary.
When you assign a value to an existing key, the new value replaces the existing value.
Removing Items :
There are several methods to remove items from a dictionary:
1. The pop() method removes the item with the specified key name.
2. The popitem() method removes the last inserted item (in versions before 3.7, a random item is removed instead).
3. The del keyword removes the item with the specified key name.
4. The del keyword can also delete the dictionary completely.
5. The clear() method empties the dictionary.
Copy a Dictionary :
You cannot copy a dictionary simply by typing dict2 = dict1, because: dict2 will only be a reference to dict1, and changes made in dict1 will automatically also be made in dict2.
There are ways to make a copy, one way is to use the built-in Dictionary method copy().
Make a copy of a dictionary with the copy() method.
Another way to make a copy is to use the built-in function dict().
Nested Dictionaries :
A dictionary can also contain many dictionaries, this is called nested dictionaries.
The dict() Constructor :
It is also possible to use the dict() constructor to make a new dictionary.
Dictionary Methods :
Python has a set of built-in methods that you can use on dictionaries.
#Python #PythonTraining #JupyterNotebook #PythonForBeginners
#Dictionary #DataTypes #Methods #Functions #TrainingProgram #Learning
---------------------------------------------------------------------------
THANK YOU so much for watching!
Please make sure to LIKE and SHARE the video and SUBSCRIBE to the channel for more such videos :)
---------------------------------------------------------------------------
CONNECT WITH ME ON:
✻ LinkedIn: / sunidhi-pandey-96008b192
✻ GitHub: https://github.com/sunidhi2001
✻ YouTube channel: / @sunidhipandey
✻ Instagram : / 20sunidhi
On this page of the site you can watch the video online Python Training Program Session 16 || Practice Example || Dictionary || Nested Dictionary & Methods with a duration of hours minute second in good quality, which was uploaded by the user Sunidhi Pandey 31 August 2021, share the link with friends and acquaintances, this video has already been watched 18 times on youtube and it was liked by 0 viewers. Enjoy your viewing!