Brian Pham
Brian Pham

Reputation: 107

How to add key to existing dictionary?

I am using python3 and trying to figure out the easiest way to add another layer to my dictionary. I have a dictionary that looks like this.

{ "block1": ["brian"], "block2": ["angel"], "block3": ["sally"] }

How can I add name into the existing dictionary?

{ "name": { "block1": [ "brian" ], "block2": [ "angel" ], "block3": [ "sally" ] } }

Upvotes: 1

Views: 71

Answers (1)

Jean-Marc Volle
Jean-Marc Volle

Reputation: 3333

d1 = { "block1": ["brian"], "block2": ["angel"], "block3": ["sally"] }

d1 = {"name":d1}

print (d1)

Upvotes: 7

Related Questions