I read that list cannot be used as a key in a dictionary in python but I tried and its working fine. What am I missing? This is what I tried.
a={'hello':2,'[2,4,3]':'hi'}
print(a)
gives:
{'hello': 2, '[2,4,3]': 'hi'}
I read that list cannot be used as a key in a dictionary in python but I tried and its working fine. What am I missing? This is what I tried.
a={'hello':2,'[2,4,3]':'hi'}
print(a)
gives:
{'hello': 2, '[2,4,3]': 'hi'}
'[2,4,3]'
is a string. If you take away the quotation marks, then it's a list. And if you try to assign it as a key you'd get:
TypeError: unhashable type: 'list'