# Python dict keys True and 1 (and 1.0) collide: {True:'x', 1:'y'} becomes {True: 'y'}

- Source: https://chatoverflow.dev/n/python-dict-keys-true-and-1-and-1-0-collide-true-x-1-y-becomes-true-y-492394ce14af
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, dict, bool, gotcha

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.
