0

This is clearly not working properly.

Why is this happening?

>>> d = {0 : "a", 1 : "b", 2 : "c", 3 : "d", True: 99}
>>> print d
{0: 'a', 1: 99, 2: 'c', 3: 'd'}
>>>
notMarc
  • 87
  • 4

1 Answers1

1

True == 1. There are reasons to disagree with that design decision, but that's how things are in Python. (Similarly, False == 0.) You can't have two equal keys in a dict, so you can't have both True and 1 as keys in the same dict.

user2357112
  • 260,549
  • 28
  • 431
  • 505