【发布时间】:2021-02-16 09:55:11
【问题描述】:
以下列表有一些重复的子列表,其中元素的顺序不同:
l1 = [
['The', 'quick', 'brown', 'fox'],
['hi', 'there'],
['jumps', 'over', 'the', 'lazy', 'dog'],
['there', 'hi'],
['jumps', 'dog', 'over','lazy', 'the'],
]
如何删除重复项,保留看到的第一个实例,以获取:
l1 = [
['The', 'quick', 'brown', 'fox'],
['hi', 'there'],
['jumps', 'over', 'the', 'lazy', 'dog'],
]
我尝试过:
[list(i) for i in set(map(tuple, l1))]
尽管如此,我不知道这是否是处理大型列表的最快方法,而且我的尝试没有按预期工作。知道如何有效地删除它们吗?
【问题讨论】:
标签: python python-3.x list list-comprehension unordered