Skip to content

Improves readability and processing time #4510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update huffman.py
  • Loading branch information
dpittaluga76 committed Jul 2, 2021
commit 36f9b64398895b0bfce22bc07c2c98894586b04e
6 changes: 4 additions & 2 deletions compression/huffman.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys


class Letter:
def __init__(self, letter, freq):
self.letter = letter
Expand Down Expand Up @@ -69,8 +70,9 @@ def huffman(file_path):
"""
letters_list = parse_file(file_path)
root = build_tree(letters_list)
letters = {k: v for letter in traverse_tree(root, "")
for k, v in letter.bitstring.items()}
letters = {
k: v for letter in traverse_tree(root, "") for k, v in letter.bitstring.items()
}
print(f"Huffman Coding of {file_path}: ")
with open(file_path) as f:
while True:
Expand Down