python list count unique 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: count unique values in python
aa="XXYYYSBAA"
bb=dict(zip(list(aa),[list(aa).count(i) for i in list(aa)]))
print(bb)
Example 3: count unique values in python
words = ['a', 'b', 'c', 'a']
unique_words = set(words)
unique_word_count = len(unique_words)
Example 4: python count unique values in list
len(set(["word1", "word1", "word2", "word3"]))