Counting and grouping
Counting and grouping are so common that collections has a tool for each.
Counter(items) counts in one line. It is a dict whose values are counts. A
missing key gives 0 instead of KeyError, and most_common(n) returns the
top n as (item, count) pairs.
defaultdict(list) is a dict that creates a fresh empty list the first time
you touch a missing key. Grouping becomes one line inside the loop:
groups[key].append(item). No if key not in groups check. defaultdict(int)
works the same way for counting.
Watch out: with a defaultdict, even reading a missing key adds it. Use in
or .get() when you only want to look.
In interviews, reaching for Counter or defaultdict shows you know the
standard library and keeps your code short.
Run it, then group the words by length instead of first letter.