Skip to content
Merged
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: 1 addition & 3 deletions data_compression/huffman.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def huffman(file_path: str) -> None:
"""
letters_list = parse_file(file_path)
root = build_tree(letters_list)
letters = {
k: v for letter in traverse_tree(root, "") for k, v in letter.bitstring.items()
}
letters = {**letter.bitstring for letter in traverse_tree(root, "")}
print(f"Huffman Coding of {file_path}: ")
with open(file_path) as f:
while True:
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 @@ -38,7 +38,7 @@ def cross(items_a, items_b):
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
)
units = {s: [u for u in unitlist if s in u] for s in squares}
peers = {s: {x for u in units[s] for x in u} - {s} for s in squares}
peers = {s: {*u for u in units[s]} - {s} for s in squares}


def test() -> None:
Expand Down
6 changes: 1 addition & 5 deletions graphs/hopcroft_karp.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ def __init__(self, graph: dict[T, list[T]]) -> None:
self.graph = graph
self.left_vertices = list(graph.keys())
self.right_vertices = sorted(
{
right_vertex
for neighbors in graph.values()
for right_vertex in neighbors
},
{*neighbors for neighbors in graph.values()},
key=repr,
)

Expand Down
2 changes: 1 addition & 1 deletion matrix/median_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def median(matrix: list[list[int]]) -> int:
3
"""
# Flatten the matrix into a sorted 1D list
linear = sorted(num for row in matrix for num in row)
linear = sorted(*row for row in matrix)

# Calculate the middle index
mid = (len(linear) - 1) // 2
Expand Down
2 changes: 1 addition & 1 deletion project_euler/problem_079/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def find_secret_passcode(logins: list[str]) -> int:
# Split each login by character e.g. '319' -> ('3', '1', '9')
split_logins = [tuple(login) for login in logins]

unique_chars = {char for login in split_logins for char in login}
unique_chars = {*login for login in split_logins}

for permutation in itertools.permutations(unique_chars):
satisfied = True
Expand Down
2 changes: 1 addition & 1 deletion sorts/bucket_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def bucket_sort(
index = min(int((val - min_value) / bucket_size), bucket_count - 1)
buckets[index].append(val)

return [val for bucket in buckets for val in sorted(bucket)]
return [*sorted(bucket) for bucket in buckets]


if __name__ == "__main__":
Expand Down
Loading