20/35
Part 5 of 7 · Every suffixLearn
A Counter of fragments was smaller for short names, and the trie for a name of 1,000 letters
The same counts also fit in a Counter keyed by the fragment itself, where a set does the once-per-name rule for free:
from collections import Counter
counts = Counter()
for name in ["ana", "anna"]:
counts.update({name[i:j] for i in range(len(name)) for j in range(i + 1, len(name) + 1)})
print(counts["a"], counts["an"], counts["nn"])
2 2 1
a shows up twice in each name, and still counts once for each: 2 names, so 2.
One name of 1,000 letters goes into a Counter of fragments. About how many letters do its fragment strings hold in all?
Pick an answer above to see the rest