What's the primary benefit of using tuples as keys in dictionaries over lists?

  • Tuples are faster to access.
  • Tuples are immutable.
  • Tuples are more memory-efficient.
  • Tuples guarantee order.
The primary benefit of using tuples as keys in dictionaries is that tuples are immutable, while lists are not. This immutability ensures that the keys won't change, making tuples suitable for use as dictionary keys. Lists can't be used as keys because they can change.
Add your answer
Loading...

Leave a comment

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