user1008636
user1008636

Reputation: 3211

Is heap (heapq) in python stable?

if heaptify this [(10,'Mike'),(20,'Jack'),(10,'Bob')]

And return the min of the heap, will it guaranteed to return (10,'Mike') and not (10,'Bob') ?

Upvotes: 4

Views: 956

Answers (1)

hiro protagonist
hiro protagonist

Reputation: 46921

no heapq is not stable. as stated in the examples of the documentation

This is similar to sorted(iterable), but unlike sorted(), this implementation is not stable.

Upvotes: 4

Related Questions