Sujet : Re: From JoyceUlysses.txt -- words occurring exactly once
De : dieter.maurer (at) *nospam* online.de
Groupes : comp.lang.pythonDate : 31. May 2024, 18:59:15
Autres entêtes
Message-ID : <mailman.76.1717182444.2909.python-list@python.org>
References : 1 2
User-Agent : VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid (x86_64-linux-gnu)
HenHanna wrote at 2024-5-30 13:03 -0700:
>
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?
Your task can be split into several subtasks:
* parse the text into words
This depends on your notion of "word".
In the simplest case, a word is any maximal sequence of non-whitespace
characters. In this case, you can use `split` for this task
* Make a list unique -- you can use `set` for this
-- Also, a list of words occurring once, twice or 3 times
For this you count the number of occurrences in a `list`.
You can use the `count` method of lists for this.
All individual subtasks are simple. I am confident that
you will be able to solve them by yourself (if you are willing
to invest a bit of time).