Thursday, March 2, 2017


Are tuples in Python hashable ?

Tuples in Python are immutable and hence should be hashable but interestingly the values of a tuple can change if the object reference of an element of the tuple is of mutable type like a list. Hence, only tuples that have immutable object references are hashable. Let's see some examples

In Python 3.5.1


As expected the same is true in Python 2.x

Note that only tuples that are hashable can be used as Dictionary keys.