import heapq

data = [2, -2, 1, -1, 0]
heap = []

for x in data:
    if x != 0:
        heapq.heappush(heap, (abs(x), x))
    else:
        if heap:
            _, patient = heapq.heappop(heap)
            print(patient)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: