Tom Ritchford
Feb 27, 2023

--

In fact, it's two lines.

from collections import Counter

print(sorted(((v, k) for k, v in Counter(open(fname).read().split()).items()), reverse=True)[:n])

This article proves my ongoing claim that any Internet comment that starts or ends with LOL is false. :-D

EDIT: tweaked to find the most common words in decreasing frequency.

--

--

Responses (1)