You can convert a list of tuples to a dict simply by converting it to a dict:
>>> a = [('policy', 871), ('insurance', 382), ('life', 357), ('request', 270), ('call', 260)]
>>> dict(a)
will result in
{'policy': 871, 'call': 260, 'life': 357, 'request': 270, 'insurance': 382}
If you want it as a json
string, try this:
>>> import json
>>> json.dumps(dict(a))
this time it will print a json formatted string instead of a dict (note the enclosing quotes):
'{"policy": 871, "call": 260, "life": 357, "request": 270, "insurance": 382}'
Update: If you need a list
of dict
s instead, try the following method:
>>> map(lambda x: {x[0]: x[1]}, a)
[{'policy': 871}, {'insurance': 382}, {'life': 357}, {'request': 270}, {'call': 260}]