You need to use a data structure as keys for a dictionary, and it must hold multiple items. Which one would you choose between lists and tuples?
- Both lists and tuples
- List
- Neither lists nor tuples
- Tuple
Tuples are the preferred choice as keys for dictionaries because they are immutable. Lists, on the other hand, are mutable and cannot be used as dictionary keys. Immutability ensures that the keys remain consistent, preventing unexpected behavior in the dictionary.
Loading...
Related Quiz
- How can you optimize the speed of a Python program that performs extensive numerical computations?
- What is the primary use of the Pandas library in Python?
- When a method is decorated with @staticmethod, it cannot access or modify _______ specific data.
- How does Python enforce the private access modifier for class members?
- How can you secure sensitive information, like API keys, in a Flask or Django application?