From b47377d53f64786f10450398f5a2291ead2438d5 Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 1 Oct 2020 11:54:34 +0200 Subject: [PATCH 1/2] fix both error of issue 739 --- contents/huffman_encoding/code/python/huffman.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contents/huffman_encoding/code/python/huffman.py b/contents/huffman_encoding/code/python/huffman.py index 1e1cc541e..81b8fc802 100644 --- a/contents/huffman_encoding/code/python/huffman.py +++ b/contents/huffman_encoding/code/python/huffman.py @@ -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 wether our tree contains more than 1 element or not + if not tree: + return [] + elif type(tree) != list: + return [(tree, '0')] codebook = [] From 2243df609eb7ffc4d5cead528e8c1c26ea823829 Mon Sep 17 00:00:00 2001 From: James Schloss Date: Mon, 12 Oct 2020 18:24:21 -0400 Subject: [PATCH 2/2] Update contents/huffman_encoding/code/python/huffman.py --- contents/huffman_encoding/code/python/huffman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contents/huffman_encoding/code/python/huffman.py b/contents/huffman_encoding/code/python/huffman.py index 81b8fc802..87fa776fa 100644 --- a/contents/huffman_encoding/code/python/huffman.py +++ b/contents/huffman_encoding/code/python/huffman.py @@ -35,7 +35,7 @@ def build_huffman_tree(message): # constructs the mapping with recursion def build_codebook(tree, code=''): - # Check wether our tree contains more than 1 element or not + # Check whether our tree contains more than 1 element or not if not tree: return [] elif type(tree) != list: