相关疑难解决方法(0)

从python中的列表中获取唯一值

我想从以下列表中获取唯一值:

['nowplaying', 'PBS', 'PBS', 'nowplaying', 'job', 'debate', 'thenandnow']
Run Code Online (Sandbox Code Playgroud)

我需要的输出是:

['nowplaying', 'PBS', 'job', 'debate', 'thenandnow']
Run Code Online (Sandbox Code Playgroud)

此代码有效:

output = []
for x in trends:
    if x not in output:
        output.append(x)
print(output)
Run Code Online (Sandbox Code Playgroud)

我应该使用更好的解决方案吗?

python

701
推荐指数
17
解决办法
138万
查看次数

标签 统计

python ×1