We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 365d32f commit cd40d6dCopy full SHA for cd40d6d
1 file changed
rounds/1_histogram/solution.py
@@ -4,11 +4,18 @@
4
passes out of the box. Replace the body of ``compute_histogram`` with your
5
own faster implementation.
6
"""
7
+from collections import defaultdict
8
9
10
def compute_histogram(path: str) -> dict[bytes, int]:
11
+
12
"""Frequency of every 2-byte bigram in the file at ``path``."""
- # TODO: remove this delegation and write your own implementation here.
- from .baseline import compute_histogram as _baseline
13
+ counts: dict[bytes, int] = defaultdict(int)
14
15
+ with open(path, "rb") as f:
16
+ data = f.read()
17
18
+ for i in range(len(data) - 1):
19
+ counts[data[i:i + 2]] += 1
20
- return _baseline(path)
21
+ return dict(counts)
0 commit comments