File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change 2
2
from collections import defaultdict
3
3
import sys
4
4
5
+
5
6
class HuffmanNode :
6
7
def __init__ (self , char = None , freq = 0 ):
7
8
self .char = char
@@ -18,7 +19,7 @@ def calculate_frequencies(file_path):
18
19
Reads the file and calculates the frequency of each character.
19
20
"""
20
21
freq = defaultdict (int )
21
- with open (file_path , 'r' ) as file :
22
+ with open (file_path , "r" ) as file :
22
23
for line in file :
23
24
for char in line :
24
25
freq [char ] += 1
@@ -67,12 +68,12 @@ def encode_file(file_path, code_map):
67
68
Encodes the file contents using the Huffman codes.
68
69
"""
69
70
encoded_output = []
70
- with open (file_path , 'r' ) as file :
71
+ with open (file_path , "r" ) as file :
71
72
for line in file :
72
73
for char in line :
73
74
encoded_output .append (code_map [char ])
74
75
75
- return '' .join (encoded_output )
76
+ return "" .join (encoded_output )
76
77
77
78
78
79
def huffman (file_path ):
You can’t perform that action at this time.
0 commit comments