Sep-24-2023, 09:02 AM
(This post was last modified: Sep-24-2023, 09:02 AM by Gribouillis.)
You could use
collections.abc.Hashable
>>> from collections.abc import Hashable >>> isinstance('spam', Hashable) True >>> isinstance([], Hashable) FalseWell, thinking again, it doesn't seem to work well for what you want to do
>>> from collections.abc import Hashable >>> isinstance((1, []), Hashable) True >>> {(1, []): 3} Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list'Then a reason to prefer
hash()
over the dict is that it doesn't attempt to build a dictionary instance.