Splitting a list of dictionaries into several lists of dictionaries

后端 未结 5 1580
刺人心
刺人心 2020-12-15 06:25

I\'ve been whacking away at this for a while to no avail... Any help would be greatly appreciated.

I have:

[{\'event\': 0, \'voltage\': 1, \'time\':         


        
5条回答
  •  [愿得一人]
    2020-12-15 07:24

    A simple implementation will suffice in my opinion:

    grouping = {}    
    for d in dictlist:
        if d[field] not in grouping:
            grouping[d[field]] = []
        grouping[d[field]].append(d)
    result = list(result.values())
    

提交回复
热议问题