Tuples Are Element-wise Hashable and Equatable
suggest changehash((1, 2)) # ok
hash(([], {"hello"})) # TypeError: unhashable type: 'list'
Thus a tuple can be put inside a set or as a key in a dict only if each of its elements can.
{(1, 2)} # ok
{([], {"hello"})} # TypeError: cannot use 'tuple' as a set element (unhashable type: 'list')
Two tuples are equal when they have the same length and corresponding elements compare equal. Equality does not require the elements to be hashable: ([1],) == ([1],) is true.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents