Python dictionary doesn't have all the keys assigned, or items

后端 未结 4 1337
刺人心
刺人心 2021-01-17 07:44

I created the following dictionary

exDict = {True: 0, False: 1, 1: \'a\', 2: \'b\'}

and when I print exDict.keys(), well, it g

4条回答
  •  甜味超标
    2021-01-17 08:11

    This happens because True == 1 (and False == 0, but you didn't have 0 as a key). You'll have to refactor your code or data somehow, because a dict considers keys to be the same if they are "equal" (rather than is).

提交回复
热议问题