How to count the number of unique values in a list in Python

The number of unique values in a list is the number of elements excluding duplicates. For example, the number of unique values in [1, 1, 2, 2, 3] is 3.

Solution for How to count the number of unique values in a list in Python : You can use set() and len() to count unique values in a list Call set(*args) with the list as *args to convert the list to a set of unique values. Call len(*args) with this new set as *args to return its length, which is the number of unique values.


how-to-count-the-number-of-unique-values-in-a-list-in-python