0
Where will I ever need to use Tuples when there's already Lists in Python
3 ответов
+ 1
Tuples are immutable, hence they can be used as keys in dictionary ( this can't be done with lists, since they are mutable) . Assuming you have a collection of data that has the same value for each tuple comes in handy for such. Example
Colors={("r", "g") :3, "b" : 2}
Colors["r", "g"] outputs 3
0
Tuples are 3 or 4 times faster in creation than lists.
Also you'll save resourses for program to not be able to modify the tuple than program to be able to modify the tuple even though it would not be done.