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'}]

  

上一篇:MVC的各个部分都有那些技术来实现?如何实现?


下一篇:【点云识别】Learning to Segment 3D Point Clouds in 2D Image Space (CVPR 2020)