如何为列表列表查找唯一项?你知道吗
在下面的例子中,我只需要两个项目。你知道吗
mylist=[[' Dish Towel .\n', '1.000', '149.000'],
[' Dish Towel .\n', '1.000', '149.000'],
[' Kitchentowel(mix designs) .\n', '1.000', '99.000'],
[' Kitchentowel(mix designs) .\n', '1.000', '99.000']]
预期结果:
newlist=[[' Dish Towel .\n', '1.000', '149.000'],
[' Kitchentowel(mix designs) .\n', '1.000', '99.000']]
我试过了,但我打错了。你知道吗
output = set()
for x in mylist:
output.add(x)
print output
您可以使用
set
保留唯一项:请注意,由于
set
只接受可哈希对象,因此需要将列表转换为元组,然后使用set
你可以尝试以下方法:
相关问题 更多 >
编程相关推荐