From JoyceUlysses.txt -- words occurring exactly once
dieter.maurer at online.de
dieter.maurer at online.de
Fri May 31 13:59:15 EDT 2024
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).
More information about the Python-list
mailing list