-4

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'}
buran
  • 13,682
  • 10
  • 36
  • 61

1 Answers1

2

'[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'

Arthur
  • 118
  • 1
  • 9