嵌套字典与重复的键但不同的值 [英] Nested dictionary with duplicate keys but different values
本文介绍了嵌套字典与重复的键但不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难在下面的嵌套字典中返回 $ t
的每个实例的值。我需要做的是拉每个键值对,并将它们单独添加到另一个字典。
I'm having a hard time returning the values of each instance of $t
in the nested dictionary below. What I need to do is pull each of the key-value pairs and add them individually to another dictionary.
这是JSON:
"breed": [
{
"$t": "Chihuahua"
},
{
"$t": "Jack Russell Terrier"
}
]
顺便说一句,我使用的是Python 2.7
By the way, I'm using Python 2.7
推荐答案
这样的东西?
>>> o = [ { "$t": "Chihuahua" }, { "$t": "Jack Russell Terrier" } ]
>>> [ item["$t"] for item in o ]
['Chihuahua', 'Jack Russell Terrier']
>>>
这篇关于嵌套字典与重复的键但不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文