Python Dictionary Methods and Dictionary Comprehension
Adding Key Value Pairs to a Dictionary
Output
Printing Dictionaries
Output
{'Satish': 'C++', 'Ram': 'Physics', 'Tom': 'Chemistry'}
C++
dict_keys(['Satish', 'Ram', 'Tom'])
dict_values(['C++', 'Physics', 'Chemistry'])
Removing Elements from a Dictionary
Output
{'Ram': 'Physics'}
Clearing Elements from a Dictionary
Output
{}
Printing the elements in a Dictionary using a For Loop
Output
Satish:C++
Ram:Physics
Tom:Chemistry
Printing Keys from a Dictionary
Output
Satish
Ram
Tom
Printing Values from a Dictionary
Output
C++
Physics
Chemistry
Dictionary Shallow Copy
Output
{'Satish': [125, 234, 435], 'Ramesh': 'C++'}
{'Satish': [125, 234, 435], 'Ramesh': 'C++'}
Creating another Dictionary using .fromkeys method
Output
{'ramesh': 'none', 'satish': 'none', 'tom': 'none'}
Creating another Dictionary from Values using .fromKeys
Output
{'satish': {1}, 'sam': {1}, 'ramesh': {1}}
Getting the value for a specific key using .get method
Output
python
None
Getting the items using the .items method
Output
satish python
ramesh physics
Exercise on setdefault method
Output
Update Method for updating the value for a specific key
Output
{'satish': 'python', 'ramesh': 'physics', 'test': 'testvalue'}
Exercises on Dictionary Comprehension
Output
{'num1': 3, 'num3': 5}
Exercise2 on Dictionary Comprehension
Output
Exercise 3 on Dictionary Comprehension
Output
{'name1': 'Satish', 'name2': 'Santosh'}
Creating Nested Dictionary
Output
{'12BCE0001': {'mobile': 9976555522, 'landline': 416222000}}
Exercise on Nested Dictionary
Output
{'mobile': 9976555522, 'landline': 416222000}
{'mobile': 8888888888, 'landline': 416222555}
Printing the Mobile Number for a Specific Student
Output
9976555522
Traversing a Nested Dictionary
Output
Printing only name fields from a Nested Dictionary
Output
Exercise on Dictionary
Output
Solution to the Exercise
Output