2 ms·
Is it really that rare, though, and if so, what makes it rare? I find that when I am doing this sort of thing, the issues seem to be the same as when writing a
by mannykannot 8y ago
Is it really that rare, though, and if so, what makes it rare? I find that when I am doing this sort of thing, the issues seem to be the same as when writing a conventional loop - in this case:
Split the stream of text into words.
Normalize with respect to case.
Accumulate a count of each distinct word.
Sort by the counts.
Print the number needed.
Furthermore, I would guess that the corner cases (such as hyphenated words) are as likely to trip someone up in either approach.
Perhaps what makes it rare is not having seen an example before - but one example is enough to demonstrate the principle, thanks to its elegant simplicity.
The hard part used to be in remembering which utility has an option that performs the transformation you are looking for, but practice helped with that, especially once one knew enough to guess which utility probably had that feature, at which point one brought up its man page. These days, of course, it is usually easy to search for the solution you want.