python - How to convert a list of tuples into list of dictionaries with plus values? -
i have list of tuples, e.g: list_of_tuples = [('company_name', 56, 'green'), ('other_company', 43, 'blue')]
i have convert list of dictionaries in python. key should company_name, , values should in list, , have add more values, like: [{'company_name' : [56, 'green', 'more_value'}, {'other_company' : [43, 'blue', 'more_value'}
]
how can this?
you can use list comprehension so
>>> [{i[0] : list(i[1:])} in list_of_tuples] [{'company_name': [56, 'green']}, {'other_company': [43, 'blue']}]
Comments
Post a Comment