Let’s check out some exercises that will help understand dictionaries better.
Exercise 8-a: Python Dictionary Value by Key
Dictionaries don't have index orders, so speaking about them regarding their first item or last item is not very correct. Next time you print a dictionary it may have a different order than you saw before. Instead they have keys, and we can use keys to call their values.
Exercise 8-c: Adding a List to Python Dictionary (Nested Data)
Dictionaries can have nested data too. Also, you can add a new key to a dictionary as they are mutable (changeable). Try to add the key "work" to dict with values shown below.
.items() method of Python dictionaries combines each key-value pair inside a tuple and returns a list of tuples. List consists of as many tuples as key-value pairs.
Thank you for visiting our website! We use essential cookies to help us understand and enhance user experience. By clicking “Accept”, you consent to the use of ALL the cookies.