您可以使用 Python 的集合 (set) 数据类型来去除重复项。将输出存储在集合中,然后将集合转换回列表以获得去除重复项后的输出。

以下是示例代码:

output = ['hello', 'world', 'hello', 'python', 'world']
unique_output = list(set(output))
print(unique_output)

输出:

['world', 'hello', 'python']

在上面的代码中,我们将输出列表存储在名为 'output' 的变量中。我们使用 set() 函数将列表转换为集合,这将自动删除所有重复项。然后,我们再次使用 list() 函数将集合转换回列表,并将其存储在名为 'unique_output' 的新变量中。最后,我们打印 'unique_output' 以查看去重后的输出。

Python 去除重复输出:使用集合数据类型

原文地址: https://www.cveoy.top/t/topic/oeR9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录