how to convert list of dict to dict

后端 未结 8 809
执笔经年
执笔经年 2020-12-12 19:00

How to convert list of dict to dict. Below is the list of dict

data = [{\'name\': \'John Doe\', \'age\': 37, \'sex\': \'M\'},
        {\'name\': \'Lisa Simp         


        
8条回答
  •  执笔经年
    2020-12-12 19:25

    With python 3.3 and above, you can use ChainMap

    A ChainMap groups multiple dicts or other mappings together to create a single, updateable view. If no maps are specified, a single empty dictionary is provided so that a new chain always has at least one mapping.

    from collections import ChainMap
    
    data = dict(ChainMap(*data))
    

提交回复
热议问题