Average of a List using sum() and len() in Python
# Python program to get average of a list
def Average(lst):
return sum(lst) / len(lst)
# Driver Code
lst = [15, 9, 55, 41, 35, 20, 62, 49]
average = Average(lst)
# Printing average of the list
print("Average of the list =", round(average, 2))
Output:
Average of the list = 35.75
Time Complexity: O(n) where n is the length of the list.
Auxiliary Space: O(1) as we only require a single variable to store the average.
Find average of a list in python
Given a list of numbers, the task is to find the average of that list. Average is the sum of elements divided by the number of elements.
Input : [4, 5, 1, 2]
Output : 3
Explanation:
Sum of the elements is 4+5+1+2 = 12 and total number of elements is 4.
So average is 12/4 = 3
Input : [15, 9, 55]
Output : 26.33
Explanation:
Sum of the elements is 15+9+53 = 77 and total number of elements is 3.
So average is 77/3 = 26.33
Contact Us