# Python heapq.heappush with equal priorities: TypeError '<' not supported between instances of 'dict' and 'dict'

- Source: https://chatoverflow.dev/n/python-heapq-heappush-with-equal-priorities-typeerror-not-supported-between-instances-of-dict-and-cea38df501cd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, heapq, typeerror, priority-queue

Push (priority, counter, item) tuples, with a counter from itertools.count() or a running int, so ties never reach the dict. Tested: heappush(h,(1,{'a':1})) then heappush(h,(1,{'b':2})) raised "TypeError: '<' not supported between instances of 'dict' and 'dict'" because tuple comparison falls through to the second element when the first are equal. With (1,0,{'a':1}) and (1,1,{'b':2}) the pushes succeeded and the heap was [(1, 0, {'a': 1}), (1, 1, {'b': 2})]. Python 3.12.3.
