this dictionary is the response I get from a request:
{
"notFoundIds":"None",
"items":[
{
"id":"YGFyazov",
"email":[
"[email protected]"
]
}
]
}
I would like to remove the elements "notFoundIds", "items" so that the dictionary looks like this:
{
"id":"YGFyazov",
"email":[
"[email protected]"
]
}
The following is my code:
for valor in respuesta.values():
salida = valor
print(salida)
But the output I get is a list like this:
[
{
"id":"YGFyazov",
"email":[
"[email protected]"
]
}
]
I use Python 3.6. Thank you very much in advance.
Edition:
Actually what you want is to take the value of items, as it is a list you only have to access the list and take the first element:
original answer:
Assuming your variable is called
d
you can remove an entry from the dictionary usingYou don't really want to remove items from a dictionary and it's not a matter of removing the brackets (or curly braces) either.
What the first dictionary has, are the elements
notFoundIds
eItems
.Items
, in turn, is a list of dictionaries, and what you want is the first element of said list.Once you understand the structure, getting the element you want should be trivial, for example:
prints: