I have the following lists:
list1 = ["Hulk", "Flash", "Tesla"]
list2 = ["green", "23", "thunder"]
list3 = ["Marvel", "DC_comics", "0.0"]
and I would like to create a dictionary like this one:
{
"eo:dict": [
{"name": "Hulk", "color": green, "company": Marvel},
{"name": "Flash", "color": red, "company": DC_comics},
{"name": "Tesla", "color": thunder, "company": 0.0},
]
}
that has to be appended in a specific position within a json file I’m creating.
I tried in this way:
keys = ["name", "company", "colours"]
eo_dict = dict(zip(keys, name,company, color))
but I got the error "_ValueError: dictionary update sequence element #0 has length 3; 2 is required_"
Could anybody give me some hints?
2
Answers
You can use this code to get the expected output:
Output:
To export as JSON:
You should try this one,
The output is like
{‘name’: ‘John’, ‘age’: 28, ‘location’: ‘New York’}