Comparing & Sorting - Two tuples or two lists are both compared by their first element, and if there is a tie, then by the second element, and so on. No further attention is paid to subsequent elements after earlier elements show a difference.
Mutability - Elements in a given list are mutable, elements in a given tuple are NOT mutable.
# Lists are mutable:>>> top_rock_list['Bohemian Rhapsody', 'Kashmir', 'Sweet Emotion', 'Fortunate Son']>>> top_rock_list[1]'Kashmir'>>> top_rock_list[1] = "Stairway to Heaven">>> top_rock_list['Bohemian Rhapsody', 'Stairway to Heaven', 'Sweet Emotion', 'Fortunate Son']
# Tuples are NOT mutable:>>> celebrity_tuple('John', 'Wayne', 90210, 'Actor', 'Male', 'Dead')>>> celebrity_tuple[5]'Dead'>>> celebrity_tuple[5]="Alive"Traceback (most recent call last):File "<stdin>", line 1, in <module>TypeError: 'tuple' object does not support item assignment
Hashtables (Dictionaries) - As hashtables (dictionaries) require that its keys are hashable and therefore immutable, only tuples can act as dictionary keys, not lists.
#Lists CAN'T act as keys for hashtables(dictionaries)>>> my_dict = {[a,b,c]:"some value"}Traceback (most recent call last):File "<stdin>", line 1, in <module>TypeError: unhashable type: 'list'
#Tuples CAN act as keys for hashtables(dictionaries)>>> my_dict = {("John","Wayne"): 90210}>>> my_dict{('John', 'Wayne'): 90210}
Differences - A posteriori, in usage
Homo vs. Heterogeneity of Elements - Generally list objects are homogenous and tuple objects are heterogeneous. That is, lists are used for objects/subjects of the same type (like all presidential candidates, or all songs, or all runners) whereas although it's not forced by), whereas tuples are more for heterogenous objects.
Looping vs. Structures - Although both allow for looping (for x in my_list...), it only really makes sense to do it for a list. Tuples are more appropriate for structuring and presenting information (%s %s residing in %s is an %s and presently %s % ("John","Wayne",90210, "Actor","Dead"))
Tuples are immutable, while lists are mutable. This point is the base the for the following ones.
Memory usage
Due to mutability, you need more memory for lists and less memory for tuples.
Extending
You can add a new element to both tuples and lists with the only difference that the id of the tuple will be changed (i.e., we’ll have a new object).
Hashing
Tuples are hashable and lists are not. It means that you can use a tuple as a key in a dictionary. The list can't be used as a key in a dictionary, whereas a tuple can be used