I have two lists
a=["USA","France","Italy"]
b=["10","5","6"]
I want the end result to be in json like this.
[{"country":"USA","wins":"10"},
{"country":"France","wins":"5"},
{"country":"Italy","wins":"6"},
]
I used zip(a,b) to join two but couldn't name it
You first have to set it up as a list, and then add the items to it
import json
jsonList = []
a=["USA","France","Italy"]
b=["10","5","6"]
for i in range(0,len(a)):
jsonList.append({"country" : a[i], "wins" : b[i]})
print(json.dumps(jsonList, indent = 1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With