0

Where will I ever need to use Tuples when there's already Lists in Python

10th Nov 2019, 2:40 AM
Meshach
Meshach - avatar
3 Réponses
+ 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
10th Nov 2019, 9:11 AM
Fabian Nwobi
Fabian Nwobi - avatar
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.
11th Nov 2019, 10:18 AM
Seb TheS
Seb TheS - avatar