- 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 program to get average heights of distinct entries
Suppose we have a set of heights there may be some duplicate entries as well. We have to find the average of distinct entries of these heights.
So, if the input is like heights = [96,25,83,96,33,83,24,25], then the output will be 52.2 because the unique elements are [96,25,83,33,24], so sum is 96 + 25 + 83 + 33 + 24 = 261, average is 261/5 = 52.2.
To solve this, we will follow these steps −
h_set := a set from heights to remove duplicates
return sum of h_set items / size of h_set set
Let us see the following implementation to get better understanding
def solve(heights): h_set = set(heights) return sum(h_set)/len(h_set) heights = [96,25,83,96,33,83,24,25] print(solve(heights))
- Count distinct entries in SAP BusinessObjects
- MySQL query to select average from distinct column of table?
- Program to find minimum number of heights to be increased to reach destination in Python
- Get the Average of Average in a single MySQL row?
- Program to find number of distinct subsequences in Python
- C# Program to get distinct element from a sequence
- Program to find length of longest distinct sublist in Python
- Adjusting the heights of individual subplots in Matplotlib in Python
- Program to find average waiting time in Python
- Python Program to Create a Class and Get All Possible Subsets from a Set of Distinct Integers
- Program to remove duplicate entries in a list in Python
- Python program to count distinct words and count frequency of them
- Program to count number of distinct substrings in s in Python
- Python program to find average score of each students from dictionary of scores
- How to get the number of entries in a Lua table?