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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *