Dictionary within another

Asked

Viewed 39 times

-2

Hello, I have a problem and I would like a solution. I want to add a dictionary inside another dictionary, but I’m not getting it... I tried to use the append and nothing. Someone help me!

dicionario1 = {"Estado": "São Paulo}
dicionario2 = {}

I want to put dictionary 1 in 2 but I don’t know how.

1 answer

1


The method append does not exist in the class dict(). What you can do is use a key inside square brackets in the first dictionary and then assign the other dictionary to that key.

dicionario["<chave>"] = outro_dicionario

See below for an example:

registros = {}

usuario1 = {"Nome": "Antônio", "Idade": 27}
usuario2 = {"Nome": "Maria", "Idade": 23}

registros["Pessoa1"] = usuario1
registros["Pessoa2"] = usuario2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.