python 列表套列表去重,列表套字典去重


raw_list = [
            ["百度", "CPY"],
            ["百度", "CPY"],
            ["京東", "CPY"],
            ["百度", "CPY", ]
        ]
new_list = [list(t) for t in set(tuple(_) for _ in raw_list)]
new_list.sort(key=raw_list.index)
print(new_list)     # [['百度', 'CPY'], ['京東', 'CPY']]

  

 

data_list = [{"a": "123", "b": "321"}, {"a": "123", "b": "321"}, {"b": "321", "a": "23"}]


seen = set()
new_l = []
for d in data_list:
    t = tuple(d.items())
    if t not in seen:
        seen.add(t)
        new_l.append(d)
print(new_l)  # [{'a': '123', 'b': '321'}, {'b': '321', 'a': '23'}]

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM