Python: Lists vs. Tuples

For Python beginners, the differences between lists and tuples might not be as clear as to those who already got some experience using them.


Let’s review the key differences between the two. hopefully, it will help you choose the right type in your code and understand that although this post called ‘lists vs. tuples’ there is no real match here. each type has his own use case.


Mutability talks about the capability of an object to change or alter. This is one of the noticeable difference between the two types.

First, let’s use list:

>>> my_list = [1,2,3]
>>> my_list[2] = 9
>>> print my_list
[1, 2, 9]

Now let’s try the same on tuple:

>>> my_tuple = (1,2,3)
>>> my_tuple[2] = 9
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment

As you can see, List is mutable in Python, which means you can change it. You can modify the current objects in a list, add new and remove them.

For tuple, all the mentioned above actions, will not work as a tuple is immutable. You can’t add or remove elements from a tuple.

Heterogeneous & Homogeneous

Tuples usually contain a heterogeneous sequence of elements, meaning the elements are of different types. Lists, on the other hand, contain homogeneous sequences which mean only one data type for the whole list.

This is, in my opinion, an interesting distinction between the two, since it’s not explicit as other and it’s more of a semantic difference.  Eventually, you can use single type in a tuple and different types in a list.

There are several analogies used to emphasize this difference. My favorite one is the ‘phone app’.  To save phone contacts, you will probably want to use a list, because your contacts properties can be changed – phone number, image, even name sometimes.

To save ‘call logs’ you will want to use tuples. Call logs are used for viewing only. You can’t change call logs content.  You don’t want anyone to change the history details. Only to watch them. (The only problem with this example might be that you can not add objects to tuples and for ‘call logs’ you would want to add additional calls. but let’s assume each time new call made, a new tuple being created 🙂  )


The size of tuple object in memory is smaller than list. but that’s only noticeable when using big objects.

>>> list = list(range(10000))
>>> tuple = tuple(range(10000))
>>> print list.__sizeof__()
>>> print tuple.__sizeof__()

As you can see, the tuple is much smaller in size than list. That makes tuple operations faster.

Dictionary identifier

You can use tuple as a dictionary identifier, but not list.

>>> li = [1,1]
>>> tu = (1,1)

>>> di = {li: 2}
TypeError: unhashable type: 'list'
>>> di = {tu: 2}

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s