Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions data_compression/huffman.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def parse_file(file_path: str) -> list[Letter]:
frequencies, then convert the dict into a list of Letters.
"""
chars: dict[str, int] = {}
with open(file_path) as f:
with open(file_path, encoding="utf-8") as f:
while True:
c = f.read(1)
if not c:
Expand Down Expand Up @@ -78,7 +78,7 @@ def huffman(file_path: str) -> None:
k: v for letter in traverse_tree(root, "") for k, v in letter.bitstring.items()
}
print(f"Huffman Coding of {file_path}: ")
with open(file_path) as f:
with open(file_path, encoding="utf-8") as f:
while True:
c = f.read(1)
if not c:
Expand Down
2 changes: 1 addition & 1 deletion data_structures/arrays/sudoku_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def unitsolved(unit):

def from_file(filename, sep="\n"):
"Parse a file into a list of strings, separated by sep."
with open(filename) as file:
with open(filename, encoding="utf-8") as file:
return file.read().strip().split(sep)


Expand Down
4 changes: 2 additions & 2 deletions searches/tabu_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def generate_neighbours(path):

dict_of_neighbours = {}

with open(path) as f:
with open(path, encoding="utf-8") as f:
for line in f:
if line.split()[0] not in dict_of_neighbours:
_list = []
Expand Down Expand Up @@ -88,7 +88,7 @@ def generate_first_solution(path, dict_of_neighbours):
will travel, if he follows the path in first_solution.
"""

with open(path) as f:
with open(path, encoding="utf-8") as f:
start_node = f.read(1)
end_node = start_node

Expand Down
2 changes: 1 addition & 1 deletion strings/detecting_english_programmatically.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def load_dictionary() -> dict[str, None]:
path = os.path.split(os.path.realpath(__file__))
english_words: dict[str, None] = {}
with open(path[0] + "/dictionary.txt") as dictionary_file:
with open(path[0] + "/dictionary.txt", encoding="utf-8") as dictionary_file:
for word in dictionary_file.read().split("\n"):
english_words[word] = None
return english_words
Expand Down
2 changes: 1 addition & 1 deletion strings/word_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_word_pattern(word: str) -> str:
import time

start_time = time.time()
with open("dictionary.txt") as in_file:
with open("dictionary.txt", encoding="utf-8") as in_file:
word_list = in_file.read().splitlines()

all_patterns: dict = {}
Expand Down
Loading