Build a DefaultDict from a Dict

One-line defaultdict initialization with existing data.

2020

from collections import defaultdict
x = {"1": 1, "2": 2}
defaultdict(int, x)

View gist

Charles Lovering © 2026