Python:从嵌套列表中删除重复的项目 [英] Python: Remove Duplicate Items from Nested list
本文介绍了Python:从嵌套列表中删除重复的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
list=[[1,2],[4,5],[3,4],[4,3],[2,1],[1,2]]
我想删除重复的项目,重复的项目可以颠倒。结果应该是:
I want to remove duplicate items, duplicated items can be reversed. The result should be :
list=[[1,2],[4,5],[3,4]]
如何在Python中实现?
How do I achieve this in Python?
推荐答案
如果订单重要,您可以随时使用OrderedDict
If the Order Matters you can always use OrderedDict
>>> unq_lst = OrderedDict()
>>> for e in lst:
unq_lst.setdefault(frozenset(e),[]).append(e)
>>> map(list, unq_lst.keys())
[[1, 2], [4, 5], [3, 4]]
这篇关于Python:从嵌套列表中删除重复的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文