File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed
Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change 22from collections import defaultdict
33import sys
44
5+
56class HuffmanNode :
67 def __init__ (self , char = None , freq = 0 ):
78 self .char = char
@@ -18,7 +19,7 @@ def calculate_frequencies(file_path):
1819 Reads the file and calculates the frequency of each character.
1920 """
2021 freq = defaultdict (int )
21- with open (file_path , 'r' ) as file :
22+ with open (file_path , "r" ) as file :
2223 for line in file :
2324 for char in line :
2425 freq [char ] += 1
@@ -67,12 +68,12 @@ def encode_file(file_path, code_map):
6768 Encodes the file contents using the Huffman codes.
6869 """
6970 encoded_output = []
70- with open (file_path , 'r' ) as file :
71+ with open (file_path , "r" ) as file :
7172 for line in file :
7273 for char in line :
7374 encoded_output .append (code_map [char ])
7475
75- return '' .join (encoded_output )
76+ return "" .join (encoded_output )
7677
7778
7879def huffman (file_path ):
You can’t perform that action at this time.
0 commit comments