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

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -