+ 3

What are the advantages and disadvantages of using tuples instead of lists.

10th Aug 2016, 11:19 AM
Draco131
Draco131 - avatar
4 Antworten
+ 14
It is a very good question. One good thing about tuples is that they use less memory. Lists use more memory. The downside is that tuples are immutable, so they can't be changed. But the good thing about that is the fact that you can use tuples in a dictionary, as a key. While you can't do so with a list. You as a programmer should choose them.
10th Aug 2016, 12:10 PM
Alireza M
Alireza M - avatar
+ 3
Advantages of Tuples * Allows you to output the whole tuple * Allows you to output a specific element * Allows you to combine * Allows you find an item using the index function * Allows you to calculat the length of your tuple NOTE THAT A LIST HAS ALL THE ABOVE CHARACTERISTICS. * Tuple uses less memory space Disadvantages of Tuples * You can't add an element but in a list you can * You can't sort a tuple but in a list you can * You can't delete an element but you can in a list * You can't replace an element but you can in a list
23rd Oct 2016, 7:04 AM
6085
6085 - avatar
+ 1
@Alireza How you can use tuples in a dictionary, as a key?
30th Apr 2017, 9:17 AM
Kaspar L. Palgi
Kaspar L. Palgi - avatar
0
If you store tuple like as I did tup=(1,2,3,4,5....n) Then you can change the key to tuple by dict_keys= tup
11th Dec 2023, 5:22 PM
S.SANKARA NAARAYANAN