How do I create a dictionary of dictionaries in Python?

1 day ago 6
ARTICLE AD BOX

I have two Python dictionaries, d1 and d2. Let them be:

d1 = {'a': 1, 'b': 2} d2 = {'a': 3, 'b': 4}

Those dicts would be united as a new one, say new_dict:

new_dict = {1: {'a': 1, 'b': 2}, 2: {'a': 3, 'b': 4}}

Would that be possible? How? I know I can do this:

new_dict = {1: d1, 2: d2}

But this doesn't seem to be smart/efficient, especially when the number of dictionaries to be appended to new_dict grows (d1, d2, d3, ..., dn).

Read Entire Article