Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from heapq import heappush
- from heapq import heappop
- # Heappop returns the element of the heap with the minimum value
- heappush(h, (1, "ccc"))
- heappush(h, (2, "bbb"))
- heappush(h, (-1, "ccc"))
- # Στα pop θα πετάξει πρώτα το tuple με το μικρότερο πρώτο στοιχείο, αυτό με το -1
- h = list()
- heappush(h, (1, "ccc"))
- heappush(h, (2, "bbb"))
- heappush(h, (-1, "ccc"))
- print(heappop(h))
- print(heappop(h))
- print(heappop(h))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement