Home

unhashable

Unhashable is a term used in programming to describe objects that cannot be hashed, meaning they do not provide a valid, stable hash value for the lifetime of the object. Hashing assigns a numeric value to an object, enabling fast lookups in data structures such as dictionaries and sets. For an object to be hashable, it must implement a hash function and have a well-defined notion of equality that is consistent with that hash.

In Python, hashability is tied to immutability and the presence of a suitable hash method. Most built-in

Objects can become hashable or remain hashable in practice by design. For example, a class can define

In summary, unhashable indicates that an object cannot participate in hashing-based collections, a constraint that affects

immutable
types,
such
as
integers,
floats,
strings,
and
tuples
of
hashable
elements,
are
hashable.
Tuples
are
hashable
only
if
all
their
elements
are
hashable.
Conversely,
mutable
containers
such
as
lists,
dictionaries,
and
sets
are
unhashable
because
their
contents
can
change,
which
would
alter
their
hash
value
and
compromise
lookup
integrity.
Attempting
to
use
an
unhashable
object
as
a
dictionary
key
or
as
a
member
of
a
set
typically
raises
a
TypeError
like
"unhashable
type:
'list'."
a
__hash__
method
and
ensure
its
instances
are
immutable
in
effect.
Dataclass
or
dataclass(frozen=True)
can
also
influence
hashability.
In
cases
where
mutability
is
unavoidable,
developers
often
use
a
hashable
proxy
(such
as
a
tuple
or
a
frozenset)
or
use
the
object
as
a
value
rather
than
a
key.
how
data
structures
like
dictionaries
and
sets
are
used.