4 ms·
> Let me know if you find a better approach. Except for the printing, this runs at about C speed because it has very little interpreter overhead: c = Coun
by raymondh 6y ago
> Let me know if you find a better approach.
Except for the printing, this runs at about C speed because it has very little interpreter overhead:
c = Counter(sys.stdin.read().casefold().split())
for word, count in c.most_common():
print(word, count)
P.S. Thanks for the kind shout-out in your article.
- benhoyt 6y agoNo problem -- defaultdict is one of my favourite Python tools! Note that the code you posted is nice for a one-liner, however, it goes against my constraint of not reading the entire file into memory (important for very large files).