Python Dictionaries and Sets: Beginner Test
This beginner Python test covers dictionaries and sets, the two hash-based collections every Python program uses. Questions check what happens when you assign to an existing key and how insertion order is kept, the difference between dict.get with a default and square-bracket lookup that raises KeyError, removing duplicates with set and case-sensitive string comparison, the set operators for intersection, difference and symmetric difference, which values are hashable and can be dictionary keys, what a for loop over a dictionary yields, counting words with get, why {} is an empty dict and not an empty set, the RuntimeError raised when a dictionary changes size during iteration, and merging dictionaries with the | operator. Every code question is a complete program you can run in the Python sandbox to check your answer. The test has 10 multiple-choice questions with correct answers and an explanation for each.
Comments