Post

PythonPython

T
Tom 234

Posted on 4th March 2024|32 views

0
votes

Python Count Unique Values In List

How can I count the number of unique values within a list in python?

Answers
P
Altaf syed

Posted on 4th March 2024

You can count the number of unique values within the list just by using set() and len() just like this 

x_list = [1, 1, 2, 2, 3, 4, 4]

x_set = set(x_list)

unique_values = len(x_set)

print(unique_values)

Output:

4

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos