+ 1
Why it is true false?
def ishashtable(x): try set={x} return True except TypeError: return False print(ishashable(2), ishashable([2])) True False it is true because set={x} in our case 2 is possible/true but why is false for [2] ?
2 ответов
+ 2
(2) and {2}are both of same type, tuple, whereas [2] is a list.
+ 1
1. Please write the code in code playground next time, because it is easier to read and understand. Or at least, if you're posting it as plain text, write it with the appropriate identation because this looks messy.
2. Use google for these kind of questions first before posting in here, because there were some threads opened in stackoverflow and similar that discussed this exact same problem, so please make an effort before you post such things.
Mutable data types like lists and dictionaries are unhashable. The only hashable data types are the immutable ones, like strings, integers...