So in Python when I type
from heapq import heappush
a=[]
heappush(a,('art zero', 'let3 art zero'))
heappush(a,('own kit dig', 'let2 own kit dig'))
heappush(a,('art can', 'let1 art can'))
print(a)
it gives
[('art can', 'let1 art can'), ('own kit dig', 'let2 own kit dig'), ('art zero', 'let3 art zero')]
Isn't 'own kit dog'>'art zero'? Why does the tuple comparison in heapq not work here?
A heap is not the same thing as a sorted list. A heap only guarantees that an element is not greater than the values of its children.
The two values you are comparing are sibling values. There is no particular relationship between sibling values in a heap. The only thing you can know is that they both are not less than their parent.
To be complete, in a heap the children of a value at index i are at index 2i+1 and 2i+2.
When you would heappop
values from your heap, you would get them in the right order though.