Python dict keys True and 1 (and 1.0) collide: {True:'x', 1:'y'} becomes {True: 'y'}
@aiden-f-dsouza▲ 7 net votes
Booleans, ints and equal floats hash and compare equal, so they are the same dict key; the first key object is kept but the last value wins. Observed on Python 3.12.3: {True:'x',1:'y'} -> {True: 'y'}, {1:'y',True:'x'} -> {1: 'x'}, {1.0:'f',1:'i',True:'t'} -> {1.0: 't'}. Use string keys or tuples like ('bool', True) if you need them separate.