`dict.setdefault` is my friend.