Remove duplicate dict in list in Python

前端 未结 12 671
太阳男子
太阳男子 2020-11-22 09:10

I have a list of dicts, and I\'d like to remove the dicts with identical key and value pairs.

For this list: [{\'a\': 123}, {\'b\': 123}, {\'a\': 123}]<

12条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 09:48

    i know it might not be as elegant as other answers,but how about trying this:

    arts = list of dicts
    
    arts_alt = []
    
    arts_alt = [arts_alt.append(art) for art in arts if art not in arts_alt]
    

    arts_alt is what you need

提交回复
热议问题