Skip to content

Commit 6d156e0

Browse files
committed
Switching to keeping track with set instead
1 parent d99cc18 commit 6d156e0

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

rounds/1_histogram/solution.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ def compute_histogram(path: str) -> dict[bytes, int]:
1111
with open(path, "rb") as f:
1212
data = f.read()
1313
counts: dict[bytes, int] = {}
14+
bigrams_seen = set()
1415
for i in range(len(data) - 1):
1516
bigram = data[i : i + 2]
16-
if bigram in counts:
17+
if bigram in bigrams_seen:
1718
counts[bigram] += 1
1819
else:
20+
bigrams_seen.add(bigram)
1921
counts[bigram] = 1
2022
return counts

0 commit comments

Comments
 (0)