- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Unique values count of each Key
When it is required to find unique values count of every key, an iteration along with the ‘append’ method is used.
Below is a demonstration of the same
my_list = [12, 33, 33, 54, 84, 16, 16, 16, 58] print("The list is :") print(my_list) filtered_list =  elem_count = 0 for item in my_list: if item not in filtered_list: elem_count += 1 filtered_list.append(item) print("The result is :") print(elem_count)
The list is : [12, 33, 33, 54, 84, 16, 16, 16, 58] The result is : 6
A list is defined and is displayed on the console.
An empty list is defined,
An integer is assigned to 0.
The original list is iterated over.
If an element present in the original list is not present in the second list, the integer is incremented by 1.
The number is appended to the empty list.
This is the output that is displayed on the console.
- Python Pandas - Display unique values present in each column
- Count unique values per groups in Python Pandas
- MySQL Query to get count of unique values?
- Primary key Vs Unique key
- Unique Key in RDBMS
- Difference between Primary Key and Unique key
- Python program to get maximum of each key Dictionary List
- Find the frequency of unique values and missing values for each column in an R data frame.
- Count unique sublists within list in Python
- Find the frequency of unique values for each column in an R data frame.
- How to count number of distinct values per field/ key in MongoDB?
- Python – Find occurrences for each value of a particular key
- How to find the number of unique values in each row of an R data frame?
- Extract Unique dictionary values in Python Program