how to uniqify a list of dict in python

后端 未结 6 1871
长发绾君心
长发绾君心 2020-12-10 01:10

I have a list:

d = [{\'x\':1, \'y\':2}, {\'x\':3, \'y\':4}, {\'x\':1, \'y\':2}]

{\'x\':1, \'y\':2} comes more than once I want

6条回答
  •  半阙折子戏
    2020-12-10 01:45

    A simple loop:

    tmp=[]
    
    for i in d:
        if i not in tmp:
            tmp.append(i)        
    tmp
    [{'x': 1, 'y': 2}, {'x': 3, 'y': 4}]
    

提交回复
热议问题