A question purely for curiosity's sake. This is obviously invalid syntax:
foo = {} foo['bar': 'baz']
It's obvious what happened, the developer moved a line out of the dictionary definition but didn't change it from the literal dictionary declaration to the assignment syntax (and has been suitably mocked as a result).
But my question is, why does Python raise TypeError: unhashable type
here rather than SyntaxError
? What type is it attempting to hash? Just doing this:
'bar': 'baz'
is a SyntaxError, as is this:
['bar': 'baz']
so I can't see what type is being created that is unhashable.
Using the colon in an indexing operation generates a slice
object, which is not hashable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With