Python Set Length: Remove Duplicates & Count Unique

In Python, you can convert a list to a set using the set() method, which automatically removes duplicate elements. Then, use the len() function to get the length of the set.

Here is an example code:

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

print(length)

The output is 7.

bannerAds