Operate heap with heapq module
What is a heap and how to use it
heap is a kind of priority queue.
from heapq import *
from random import shuffle
# from w ww .j a v a 2 s . c o m
data = range(10)
shuffle(data)
heap = []
for n in data:
heappush(heap, n)
print heap
heappush(heap, 0.5)
print heap
The code above generates the following result.