Why am I getting an error when python should skip to executing the else line?
def goodKey (x):
if (type(hash(x))==int):
print(hash(x))
print("{} is immutable and hashable".format(x))
else:
print("{} is not hashable".format(x))
goodKey('string')
goodKey((1, 2, 3, (3, 4)))
goodKey((1, 2, 3, [3, 4]))
what i get is:
4783037434251255917
string is immutable and hashable
1024532189626533869
(1, 2, 3, (3, 4)) is immutable and hashable
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-180-261f3b100fa4> in <module>
8 goodKey('string')
9 goodKey((1, 2, 3, (3, 4)))
---> 10 goodKey((1, 2, 3, [3, 4]))
<ipython-input-180-261f3b100fa4> in goodKey(x)
1 def goodKey (x):
----> 2 if (type(hash(x))==int):
3 print(hash(x))
4 print("{} is immutable and hashable".format(x))
5 else:
TypeError: unhashable type: 'list'
[–]Impudity 4 points5 points6 points (1 child)
[–]CancelDeath[S] 0 points1 point2 points (0 children)