From JoyceUlysses.txt -- words occurring exactly once

Pieter van Oostrum pieter-l at vanoostrum.org
Fri May 31 08:39:37 EDT 2024


HenHanna <HenHanna at devnull.tb> writes:

> Given a text file of a novel (JoyceUlysses.txt) ...
>
> could someone give me a pretty fast (and simple) Python program that'd
> give me a list of all words occurring exactly once?
>
>               -- Also, a list of words occurring once, twice or 3 times
>
>
>
> re: hyphenated words        (you can treat it anyway you like)
>
>        but ideally, i'd treat  [editor-in-chief]
>                                [go-ahead]  [pen-knife]
>                                [know-how]  [far-fetched] ...
>        as one unit.
>

That is a famous Unix task : (Sorry, no Python)

grep -o '\w*' JoyceUlysses.txt | sort | uniq -c | sort -n


-- 
Pieter van Oostrum <pieter at vanoostrum.org>
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]


More information about the Python-list mailing list