@@ -47,10 +47,11 @@ def build_tree(letters: list[Letter]) -> Letter | TreeNode:
47
47
Run through the list of Letters and build the min heap
48
48
for the Huffman Tree.
49
49
50
- >>> result_from_parse_file_func
51
- [T:1, x:1, c:1, o:1, a:1, d:1, f:1, l:1, s:2, h:3, n:3, i:5, t:5, e:5, :7]
52
- >>> build_tree(result_from_parse_file_func)
53
- <__main__.TreeNode object at 0x7fb08adff810>
50
+ # >>> result_from_parse_file_func = parse_file('file_to_read.txt')
51
+ # >>> result_from_parse_file_func
52
+ # [T:1, x:1, c:1, o:1, a:1, d:1, f:1, l:1, s:2, h:3, n:3, i:5, t:5, e:5, :7]
53
+ # >>> build_tree(result_from_parse_file_func)
54
+ # <__main__.TreeNode object at 0x7fb08adff810>
54
55
55
56
"""
56
57
response : list [Letter | TreeNode ] = letters # type: ignore
@@ -69,10 +70,12 @@ def traverse_tree(root: Letter | TreeNode, bitstring: str) -> list[Letter]:
69
70
Recursively traverse the Huffman Tree to set each
70
71
Letter's bitstring dictionary, and return the list of Letters
71
72
72
- >>> result_from_build_tree_func
73
- <__main__.TreeNode object at 0x7fb08adff810>
74
- >>> traverse_tree(result_from_build_tree_func, "")
75
- [n:3, s:2, T:1, x:1, c:1, o:1, a:1, d:1, i:5, t:5, e:5, f:1, l:1, h:3, :7]
73
+ # >>> result_from_parse_file_func = parse_file('file_to_read.txt')
74
+ # >>> result_from_build_tree_func = build_tree(result_from_parse_file_func)
75
+ # >>> result_from_build_tree_func
76
+ # <huffman.TreeNode object at 0x10c0cf8c0>
77
+ # >>> traverse_tree(result_from_build_tree_func, "")
78
+ # [n:3, s:2, T:1, x:1, c:1, o:1, a:1, d:1, i:5, t:5, e:5, f:1, l:1, h:3, :7]
76
79
77
80
"""
78
81
if isinstance (root , Letter ):
@@ -91,15 +94,19 @@ def huffman(file_path: str) -> None:
91
94
again, using the letters dictionary to find and print out the
92
95
bitstring for each letter.
93
96
94
- >>> file_path = 'file_to_read.txt'
95
- >>> print(open(file_path, 'r').read()) # showing content of file
96
- This is the text contained in the file
97
- >>> huffman(file_path)
98
- Huffman Coding of file_to_read.txt:
99
- 00110 1101 011 0010 111 011 0010 111 100 1101 101 111 100 101 00111 \
100
- 100 111 01000 01001 000 100 01010 011 000 101 01011 111 011 000 111 \
101
- 100 1101 101 111 11000 011 11001 101
102
- None
97
+ # >>> file_path = 'file_to_read.txt'
98
+ # >>> print(open(file_path, 'r').read())
99
+ # This is the text contained in the file
100
+
101
+ ### huffman algorithm returns dynamic encoding depending on how
102
+ ### the 0s and 1s are assigned
103
+
104
+ # >>> huffman(file_path)
105
+ # Huffman Coding of file_to_read.txt:
106
+ # 00110 1101 011 0010 111 011 0010 111 100 1101 101 111 100 101 00111 \
107
+ # 100 111 01000 01001 000 100 01010 011 000 101 01011 111 011 000 111 \
108
+ # 100 1101 101 111 11000 011 11001 101
109
+ # None
103
110
104
111
"""
105
112
letters_list = parse_file (file_path )
0 commit comments