How to initialize defaultdict with keys?
From the comments, I’m assuming you want a dictionary that fits the following conditions: Is initialized with set of keys with an empty list value for each Has defaultdict behavior that can initialize an empty list for non-existing keys @Aaron_lab has the right method, but there’s a slightly cleaner way: d = defaultdict(list,{ k:[] for … Read more