2016-11-15 49 views
0

还有就是我有来源:如何在python中创建自定义字典?

"VirtualizationType": "hvm", 
"Tags": [ 
     { 
      "Value": "Test", 
      "Key": "Name" 
     } 
     ] 

这里有点我的代码:与标签

for item in result: 
    temp = {"Tags": item["Value"], "VirtualizationType": item["VirtualizationType"]} 
     output.append(temp) 

我可以轻松导出VirtualizationType但couldn`t做

回答

0

如何在Python中创建字典的示例,从docs

tel = {'jack': 4098, 'sape': 4139} 

在这个例子中jacksnape是键,40984139是的值。

值也可以是字符串,并像你的情况字典的名单, 你的代码可以修改成这样:

dictionary = {"Virtualization Type" : "hvm", "Tags" : [{"Value" : "Test", "Key" : "Name"}] } #Runs in the python interpreter with no errors 
+0

我有循环行驶的问题。无论如何,我试图去.get()“标签”。 –

+0

@ user3729941你应该更多地解释你的问题。 –

+0

香港专业教育学院找到了答案: '高清find_value(标签): 值= “” 如果没有标签:返回值 为标签在标签: VAL = tag.get( “钥匙”,无) 如果val = =“值”: value = tag [“Value”] 返回值# –