Use defaultdict instead of extra key logic.