Show how Python's defaultdict removes the need for a membership check when grouping values by key.
Grouping values usually needs a check. You ask whether the key is already there, and if it is not, you create an empty container first and then add to it. A defaultdict makes that check for you.
from collections import defaultdict
words = ['apple', 'avocado', 'banana', 'blueberry', 'cherry']
groups = defaultdict(list)
for word in words:
groups[word[0]].append(word)
print(dict(groups))
The result is a mapping from the first letter to the words that begin with it. The letter a holds apple and avocado, the letter b holds banana and blueberry, and the letter c holds cherry.
Compare that with the plain dictionary version, which needs four extra lines. You write an if statement that tests whether the key is present, an assignment that creates an empty list when it is not, and the append itself. The defaultdict version is a single line, because the container is created the moment you need it.
The default factory is the argument that you pass in. Passing list creates an empty list for a missing key, int creates a zero, set creates an empty set, and str creates an empty string. The kind of factory decides what you get back, so it has to match what your code is about to do with the value.
Two related types in the same module are worth knowing. Counter is a defaultdict with an integer factory, so counting becomes counts[word] += 1 with no setup at all. OrderedDict exists for code that needs explicit reordering, although since Python 3.7 a plain dictionary already keeps the insertion order.