Remove duplicates key from list of dictionaries python

后端 未结 4 556
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 14:26

I am trying to remove the duplicates from following list

 distinct_cur = [{\'rtc\': 0, \'vf\': 0, \'mtc\': 0, \'doc\': \'good job\', \'foc\': 195, \'st\': 0         


        
4条回答
  •  别那么骄傲
    2021-01-05 15:10

    One liner to deduplicate the list of dictionaries distinct_cur on the primary_key of doc

    [i for n, i in enumerate(distinct_cur) if i.get('doc') not in [y.get('doc') for y in distinct_cur[n + 1:]]]
    

提交回复
热议问题