We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Sets
- Introduction to Sets
- Discussions
Introduction to Sets
Introduction to Sets
+ 0 comments God, who would have thought that the remaining identical numbers when calculating the average give an additional 0.7750000000000057 .............AAAAAAAA mathematics what's wrong with you
+ 0 comments def average(array): return sum(set(array))/len(set(array))
+ 0 comments This is no one-liner for beginners to understand better. And, it doesn't use more space by creating extra variable. Prolly, the best code for anyone(amateur or pro).
def average(array): distinct_heights = set(array) return (sum(distinct_heights)/len(distinct_heights)) if __name__ == '__main__': n = int(input()) arr = list(map(int, input().split())) result = average(arr) print(result)
+ 0 comments def average(array): s = set(array) return round(sum(s) / len(s), 3)
+ 0 comments - def average(array):
- set_array = set(array)
- average_count = sum(set_array)/len(set_array)
- return f'%.3f' % average_count
- if name == 'main':
- n = int(input())
- arr = list(map(int, input().split()))
- result = average(arr)
- print(result)
- def average(array):
Load more conversations
Sort 497 Discussions, By:
Please Login in order to post a comment