【发布时间】:2015-02-26 23:50:47
【问题描述】:
如果我有这样的清单:
mylist = [[1,2,3], ['a', 'c'], [3,4,5],[1,2], [3,4,5], ['a', 'c'], [3,4,5], [1,2]]
删除重复子列表的最佳方法是什么?
现在我用this:
y, s = [ ], set( )
for t in mylist:
w = tuple( sorted( t ) )
if not w in s:
y.append( t )
s.add( w )
它有效,但我想知道是否有更好的方法?更像 python 的东西?
【问题讨论】:
-
我不想更改订单。
-
那么 icoez 是你应该使用的答案,
[1,2]是[2,1]的骗子吗? -
您接受的答案没有保持顺序,集合没有任何顺序
标签: python list duplicates duplicate-removal