The PriorityQueue class sorts its objects as indicated by:
The lowest valued entries are retrieved first (the lowest valued entry is the one returned by sorted(list(entries))[0]).
When this is called on your objects that don't have an __lt__ method, it throws a TypeError.
To circumvent this, object IDs can be used instead of adding the object to the PriorityQueue. Python object IDs are globally unique, can can be obtained by calling id(object).
You can create a hashtable (dictionary) that has object ids as keys, and the object as the value.
pq = PriorityQueue()
list_node_A = ListNode(2)
list_node_B = ListNode(1)
for list_node in [list_node_A, list_node_B]:
object_dictionary[id(list_node)] = list_node # create id reference in dict
pq.put((list_node.val, id(list_node)) # put into queue
list_node_id = pq.get() # get out of queue (id)
list_node = object_dictionary[list_node_id] # get object from dict by id
i was using heapq, I insert the counter value as well.