remove duplicates from nested dictionaries in list

前端 未结 6 1882
逝去的感伤
逝去的感伤 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:13

    If I understand correctly, you want to discard matches that come later in the original list but do not care about the order of the resulting list, so:

    (Tested with 2.5.2)

    tempDict = {}
    for d in L[::-1]:
        tempDict[(d["value3"],d["value4"])] = d
    L[:] = tempDict.itervalues()
    tempDict = None
    

提交回复
热议问题