首页 > 编程语言 > 详细

python 列表套列表去重

时间:2020-09-15 10:43:52      阅读:66      评论:0      收藏:0      [点我收藏+]
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‘}]

  

python 列表套列表去重

原文:https://www.cnblogs.com/a438842265/p/13671048.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!