A package that visualizes heapq heaps
Project description
Python's heapq
can be confusing to beginners.
This package helps beginners better visualize heapq
heaps better
Quickstart
Context
What is a heap?
- a heap is a binary tree
- a binary tree where every parent <= its children
- more specifically, this is known as a min heap
- max heaps are heaps where every parent >= its children, but max heaps are not relevant here
Where heapq
comes in
heapq
is a built-in Python module- it provides us with functionality to use heaps (min heaps)
- these heaps can act like priority queues
import heapq
priority_queue: list[int] = [] # heaps are stored as lists in heapq
heapq.heappush(priority_queue, 5)
heapq.heappush(priority_queue, 10)
heapq.heappush(priority_queue, 2)
heapq.heappush(priority_queue, 6)
heapq.heappush(priority_queue, 1)
print(priority_queue) # [1, 2, 5, 10, 6]
print(heapq.heappop(priority_queue)) # 1
print(heapq.heappop(priority_queue)) # 2
print(heapq.heappop(priority_queue)) # 5
print(heapq.heappop(priority_queue)) # 6
print(heapq.heappop(priority_queue)) # 10
The weird thing about heaps in heapq
- there is no Heap object.
- heaps are stored as normal lists in
heapq
- which can be confusing for a beginner
As such, this package aims to make things more intuitive by allowing users to print and visualize a heapq
heap (which is actually a list) directly.
Documentation Link: https://docs.python.org/3/library/heapq.html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
visualize_heapq-0.0.2.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file visualize_heapq-0.0.2.tar.gz
.
File metadata
- Download URL: visualize_heapq-0.0.2.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3bd0efffa080dc383b1e5a40d86d67dc029533966e868e6245b15de9b6470ce |
|
MD5 | 9307cc9b748fc4d321d80d7ba2a3a856 |
|
BLAKE2b-256 | e9e799f56279c09b3c56cc9e7f40381a34856e429bb9fd55e523473a9f5d54fd |
File details
Details for the file visualize_heapq-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: visualize_heapq-0.0.2-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f33c0034771db1ac5ae1f0644dc8d047b4af419be69aa3d94fb0b1608a8cd53 |
|
MD5 | 5f81fed9146ba039417c4f0f6f33b215 |
|
BLAKE2b-256 | de9bd1ee7edab98809bc9a5c6eeb324a485a2cc10c71542570668989adf3ecd2 |