简体   繁体   中英

How to create a custom dictionary in python?

There is what i have in source:

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

and here is a bit of my code:

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

I can easily export VirtualizationType but couldn`t do it with Tags

An example of how to create a dictionary in Python, from docs :

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

In this example jack , snape are the keys and 4098 , 4139 are the values.

Values can also be strings and a list of dictionary like in your case, your code can modified into this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM