-2
d={['R', 'P']:2,['R', 'S']:1,['P','S']:2}

trying to create this list to make the game rock paper scissors but i get an error, TypeError: unhashable type: 'list' looks like the list in the dict makes the error, any solve?

Ori
  • 67
  • 5
  • 1
    You can't, exactly due to the reason explained in the error. You can however use tuples. – DeepSpace Jan 12 '21 at 20:06
  • see this why you cannot https://stackoverflow.com/questions/7257588/why-cant-i-use-a-list-as-a-dict-key-in-python Replacing with tuples will do. – Bing Wang Jan 12 '21 at 20:07

1 Answers1

0

You cannot use lists as keys in dictionary (or any non-hashable/mutable type). You can use tuples instead

d={('R', 'P'):2,('R', 'S'):1,('P','S'):2}
C_Z_
  • 7,427
  • 5
  • 44
  • 81