I have the list below:
rainbow = ['green', 'red', 'blue', 'yellow' ,'orange']
and I would like the output to be a JSON object like so:
{
"rainbow":[
{
"color": "green"
},
{
"color": "red"
},
{
"color": "blue"
},
{
"color": "yellow"
}
{
"color": "orange"
}
]}
any ideas? I've tried a couple of things and been struggling to find a solution.
import json
import itertools
rainbow = ['green', 'red', 'blue', 'yellow' ,'orange']
d = dict((k,'color') for k in rainbow)
skittles = json.dumps(d)
print skittles
{"blue": "color", "orange": "color", "green": "color", "yellow": "color", "red": "color"}