TIL: Python's defaultdict takes a factory function
Briefly

The defaultdict is a dictionary-like object in Python that allows you to define default values for non-existent keys using a callable function, enhancing flexibility.
Using a callable function with defaultdict creates dynamic defaults; for instance, with a lambda and random.randint, it can return random integers between 1 and 100.
Read at daniel.feldroy.com
[
|
]