# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Heapq

# This object can work with lists and dicts, automatizing some functions.
#
# We need to import heapq

import heapq

# There are some important funcions

# ##  heappush

# Insert an element

h = []
h

heapq.heappush(h,2)
heapq.heappush(h,13)
heapq.heappush(h,5)
heapq.heappush(h,7)
heapq.heappush(h,11)
h

# ## heapop

# Return the lower value and pop it out of the object.

m = heapq.heappop(h)
print("We removed {} and now the list is {}".format(m,h))

m = heapq.heappop(h)
print("We removed {} and now the list is {}".format(m,h))

m = heapq.heappop(h)
print("We removed {} and now the list is {}".format(m,h))

StarcoderdataJupyterScriptsDedupFiltered