π
Text vitals
Break any text down into lines, words, letters, and vowel percentages.
MakerΒ· ages 12β1430 minCounterlist comprehensionsstring methodsmax/min
textstats.py
β¦First load pulls ~10Β MB of Python. Only happens once β the browser caches it after.
What should the output look like?
You should see counts of lines/words/letters/vowels, the longest word, and top 5 most-common letters.
π
How this works
Counter from collections is a dict that counts things for you. List comprehensions with if filter what you don't want. max(words, key=len) finds the longest word β same trick as sorted.
Your turn β try these
- 1Count how many words start with each letter of the alphabet.
- 2Add the average word length in letters.
- 3Detect if the text looks like a poem (short lines) or prose (long lines).