【发布时间】:2012-06-19 00:49:51
【问题描述】:
可能重复:
How do you remove duplicates from a list in Python whilst preserving order?
Does Python have an ordered set?
我发现自己经常做以下事情:
list_of_items # I have a list of items
set(list_of_items) # I want to remove duplicates
但是,在转换为 set 时,我失去了列表中的初始排序,这很重要。
删除列表中的重复项并保持列表的初始(相对)顺序的最佳方法是什么?
【问题讨论】:
-
绝对是重复的。其中一个答案也与@Levon 提到的重复问题的答案几乎重复。
标签: python