Skip to content

fix both error of issue 739 #756

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 2 commits into from
Oct 12, 2020
Merged
Changes from all commits
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
8 changes: 7 additions & 1 deletion contents/huffman_encoding/code/python/huffman.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ def build_huffman_tree(message):
# insert the new tree there
trees.insert(index, (new_tree, new_weight))

huffman_tree = trees[0][0]
# Return an empty list if the message was empty, else the tree
huffman_tree = [] if not trees else trees[0][0]
return huffman_tree

# constructs the mapping with recursion
def build_codebook(tree, code=''):
# Check whether our tree contains more than 1 element or not
if not tree:
return []
elif type(tree) != list:
return [(tree, '0')]

codebook = []

Expand Down