remove duplicates from nested dictionaries in list

前端 未结 6 1883
逝去的感伤
逝去的感伤 2021-02-06 16:13

quick and very basic newbie question.

If i have list of dictionaries looking like this:

L = []
L.append({\"value1\": value1, \"value2\": value2, \"value3         


        
6条回答
  •  失恋的感觉
    2021-02-06 17:14

    Here's one way:

    keyfunc = lambda d: (d['value3'], d['value4'])
    
    from itertools import groupby
    giter = groupby(sorted(L, key=keyfunc), keyfunc)
    
    L2 = [g[1].next() for g in giter]
    print L2
    

提交回复
热议问题