Dashboard

Module 21: Working with Dictionaries

Test your knowledge! Answer 10 questions. You need at least 6 correct answers to pass (). You can retake the quiz as many times as needed. Good luck!

1Which method is commonly used to iterate over only the keys of a dictionary called `my_dict`?

2How can you get a list of all values from a dictionary `student_grades`?

3What does the `items()` method return when called on a dictionary?

4How do you check if a key named `'city'` exists in a dictionary `user_profile`?

5What is the primary purpose of the `del` keyword when used with a dictionary item like `del data['temp']`?

6Consider `inventory = {'apples': 10, 'bananas': 5}`. What happens if you execute `removed_item = inventory.pop('oranges', 0)`?

7Which method allows you to get a value for a key but returns a default value (e.g., `None` or a specified value) if the key is not found, without raising an error?

8If you iterate through a dictionary using `for k, v in my_dict.items():`, what do `k` and `v` represent in each iteration?

9What is the result of `len({'name': 'Alice', 'age': 30, 'city': 'New York'})`?

10Which of the following correctly creates an empty dictionary?