6 Words count: Reading files and STDIN, iterating lists, formatting strings
“I love to count!”
--Count von Count
Counting things is a surprisingly important programming skill. Maybe you’re trying to find out how many pizzas were sold each quarter or how many times you see certain words in a set of documents. Usually the data we deal with in computing comes to us in files, so in this chapter, we’re going to push a little further into reading files and manipulating strings. |
We’re going to write a Python version of the venerable wc
(“word count”) program. Ours will be called wc.py, and it will count the lines, words, and bytes found in ...
Get Tiny Python Projects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.