+ 1
Why there is an error
bad_dict = { [1, 2, 3]: "one two three", }
3 Respostas
+ 4
because dictionaries only can have immutable keys, int, strings and tuples by example.
in your example, the list [1,2,3] is a invalid key because the list is a mutable data type.
+ 2
The key of dictionary should be hashable, but list is unhashable so that code gives you error.
0
This appears (to me) to mix the syntax for dictionaries:
{index:value, index:value, ...}
lists...in this case I'd expect it on the right hand side of equals (=):
... = [value, value, value]
and assignment (left-hand side of equals):
a = value
a,b = value1,value2
[a,b] = [value1, value2]
*** Note...this does NOT fix it:
{
[1,2,3]:["a","b","c"]
}
TypeError: unhashable type: 'list'
Which brings me back to mixing syntax.