Capstone: word counter
This is the function every text-processing tool eventually needs: split text
into words, then count how often each one shows up. It's also everything from
this module in one place - a loop, a dict, string methods, and a default value
for keys you haven't seen yet.
text.lower().split() lowercases the whole string, then splits it into a list
of words on whitespace. counts.get(word, 0) reads a dict value that might not
exist yet, falling back to 0 instead of raising - exactly what you need to
build up counts one word at a time.
Your task: write word_count(text), returning a dict mapping each lowercase
word to how many times it appears in text.
You'll practice:
- Splitting and lowercasing a string
- Building up a dict with
.get(key, default)