fork download
  1. from heapq import heapify
  2. from random import sample
  3.  
  4. def is_minheap(lst):
  5. return all(lst[i] >= lst[i - 1 >> 1] for i in range(1, len(lst)))
  6.  
  7. lst = sample(range(10), 10)
  8. print(is_minheap(lst), lst)
  9. heapify(lst)
  10. print(is_minheap(lst), lst)
Success #stdin #stdout 0.04s 10052KB
stdin
Standard input is empty
stdout
False [1, 2, 6, 8, 0, 5, 3, 9, 7, 4]
True [0, 1, 3, 7, 2, 5, 6, 9, 8, 4]