Computer Science
When would you prefer tuples over lists ?
Python Tuples
6 Likes
Answer
Tuples are preferred over lists in the following cases:
- When we want to ensure that data is not changed accidentally. Tuples being immutable do not allow any changes in its data.
- When we want faster access to data that will not change as tuples are faster than lists.
- When we want to use the data as a key in a dictionary. Tuples can be used as keys in a dictionary, but lists cannot.
- When we want to use the data as an element of a set. Tuples can be used as elements of a set, but lists cannot.
Answered By
4 Likes