温馨提示×

stream去重以后怎么获取集合长度

小亿
90
2024-02-02 17:20:42
栏目: 编程语言

在Python中,可以使用set()方法将列表转换为集合,并自动去除重复元素。然后,使用len()函数获取集合的长度。

以下是一个示例代码:

stream = [1, 2, 3, 4, 4, 5, 5, 6, 7, 7]
unique_stream = set(stream)
length = len(unique_stream)

print(length)

输出结果为:7

0