number of unique elements in list python code example
Example 1: python count number of unique elements in a list
len(set(my_list))
my_list = ['so', 'so', 'so', 'many', 'duplicated', 'words']
len(set(my_list))
--> 4
Example 2: python list with only unique values
my_list = list(set(my_list))
Example 3: how to find unique values in list in python
mylist = ['nowplaying', 'PBS', 'PBS', 'nowplaying', 'job', 'debate', 'thenandnow']
myset = set(mylist)
print(myset)
Example 4: python count unique values in list
len(set(["word1", "word1", "word2", "word3"]))