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

ios - Is 'init' forbidden as *part* of a variable name? -

file - Python: AttributeError: 'str' object has no attribute 'readlines' -

c# - Get the Class name in a class with atribute inside a attribute method -