如何从列表中获取一组值,以便集合的顺序使得列表中的顺序仍保留在集合中?

时间:2018-02-10 08:32:46

标签: python list set

我实际代码中的列表太大了 有没有办法获得所需的输出 一种有效的方式将是首选 这是我的代码:

import sys
def function():
    listt=["the","cat","sat","on","the","mat","which","is","on","the","floor"]
    print (sorted(set(listt)))
function()

Output:['cat', 'floor', 'is', 'mat', 'on', 'sat', 'the', 'which']
Expected Output:["the","cat","sat","on","mat","which","is","floor"]

0 个答案:

没有答案