heapq

 1import heapq
 2
 3q = [3, 1, 2, 5]
 4heapq.heapify(q)
 5
 6print(len(q))
 7
 8while q:
 9    print(heapq.heappop(q))
10
11q = [3, 1, 2, 5]
12heapq.heapify(q)
13
14for i in range(len(q)):
15    print(heapq.heappop(q))