Code 3: Count Unique Elements in a List in Python in two ways | 365 Days of Code

Опубликовано: 31 Октябрь 2024
на канале: Code House
740
5

Python program to count the unique elements in a List.

Code -
Count of unique elements
data = [34,90,20,48,23,90,23] # Sol is 5
Method 1
print(len(set(data)))

Method 2
unique_list = []
for each in data:
if each not in unique_list:
unique_list.append(each)
print("Unique count is ", len(unique_list))