나는 이렇게 학습한다/Algorithm & SQL
0918. Grasshopper - Array Mean
daco2020
2022. 9. 19. 00:20
Find Mean
Find the mean (average) of a list of numbers in an array.
Information
To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list.
For an example list of 1, 3, 5, 7
- Add all of the numbers
1+3+5+7 = 16
- Divide by the number of values in the list. In this example there are 4 numbers in the list.
16/4 = 4
- The mean (or average) of this list is 4
Solution:
def get_sum(func):
def wrapper(nums):
return func(sum(nums), len(nums))
return wrapper
@get_sum
def find_average(sum, count):
return sum / count if count else 0