Prerequisites: sum() function, len() function, round() function, reduce(), lambda, and mean().

Given a list of numbers, the task is to find average of that list. Average is the sum of elements divided by the number of elements.

Examples:

Input : [4, 5, 1, 2, 9, 7, 10, 8] Output : Average of the list = 5.75Explanation: Sum of the elements is 4+5+1+2+9+7+10+8 = 46 and total number of elements is 8. So average is 46 / 8 = 5.75 Input : [15, 9, 55, 41, 35, 20, 62, 49] Output : Average of the list = 35.75Explanation: Sum of the elements is 15+9+55+41+35+20+62+49 = 286 and total number of elements is 8. So average is 46 / 8 = 35.75

**Using sum()**

In Python we can find the average of a list by simply using the **sum()** and **len()** function.

**sum()**: Using sum() function we can get the sum of the list.**len()**: len() function is used to get the length or the number of elements in a list.

`# 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` `)) ` |

*chevron_right*

*filter_none*

Output:

Average of the list = 35.75

**Using reduce() and lambda**

We can use the reduce() to reduce the loop and by using the lambda function can compute summation of list. We use len() to calculate length as discussed above.

`# Python program to get average of a list ` `# Using reduce() and lambda ` ` ` `# importing reduce() ` `from` `functools ` `import` `reduce` ` ` `def` `Average(lst): ` ` ` `return` `reduce` `(` `lambda` `a, b: a ` `+` `b, 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` `)) ` |

*chevron_right*

*filter_none*

Output:

Average of the list = 35.75

**Using mean()**

The inbuilt function mean() can be used to calculate the mean( average ) of the list.

`# Python program to get average of a list ` `# Using mean() ` ` ` `# importing mean() ` `from` `statistics ` `import` `mean ` ` ` `def` `Average(lst): ` ` ` `return` `mean(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` `)) ` |

*chevron_right*

*filter_none*

Output:

Average of the list = 35.75

## Recommended Posts:

- Find sum and average of List in Python
- Python | Average of each n-length consecutive segment in a list
- Python | Average String length in list
- Python | Record elements Average in List
- Python | Column Average in Record List
- Python - Rear elements Average in List
- Python - Average digits count in a List
- Find the average of an unknown number of inputs in Python
- Python | Average of two lists
- Python | Replace NaN values with average of columns
- Numpy MaskedArray.average() function | Python
- Python | Average of Float Numbers
- Python - Get Random Range Average
- Calculate the average, variance and standard deviation in Python using NumPy
- Python - Average of digit greater than K
- Background Subtraction in an Image using Concept of Running Average
- Multilabel Ranking Metrics-Label Ranking Average Precision | ML
- Average of Cubes of first N natural numbers
- PyQt5 QSpinBox - Getting average character width
- PyQt5 - Average Speed Calculator

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.