From JoyceUlysses.txt -- words occurring exactly once
Grant Edwards
grant.b.edwards at gmail.com
Fri May 31 14:58:55 EDT 2024
On 2024-05-31, Pieter van Oostrum via Python-list <python-list at python.org> wrote:
> 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
Yep, that's what came to my mind (though I couldn't remember the exact
grep option without looking it up). However, I assume that doesn't
get you very many points on a homework assignemnt from an "Intruction
to Python" class.
More information about the Python-list
mailing list