9 examples of 'how to find the average of a list in python' in Python

Every line of 'how to find the average of a list in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
74def average(item):
75 # This sums all the items of a parameter, in this program's case the parameters are lists.
76 summing = sum(item)
77 # This counts the number of items in the lists.
78 counting = len(item)
79 # This divides the total sum by the amount of items.
80 result = summing / counting
81 # This returns the average.
82 return result
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

104def test_averageOnList(self):
105 items = [0, 8, 4, 10]
106 res = BlocklyMethods.averageOnList(items)
107 self.assertEqual(5.5, res)
59def average(average_window, data):
60 window = []
61 newdata = []
62 for v in data:
63 window.append(v)
64 if len(window) == average_window:
65 newdata.append(sum(window)/average_window)
66 del window[0]
67 return newdata
36def average(a,b):
37 return tuple(0.5*(a[i]+b[i]) for i in range(len(a)))
11def avg(l):
12 """
13 Returns the average between list elements
14 """
15 return (sum(l)/float(len(l)))
159def mean_list(x, y):
160 res = []
161 for i, j in zip(x, y):
162 res.append(round(mean(i, j), 3))
163 return res
220def getAverage(seq):
221 """
222 Finds the average of <seq>
223 >>> getAverage(['3', 9.4, '0.8888', 5, 1.344444, '3', '5', 6, '7'])
224 4.033320571428571
225 """
226 return sum(seq) / len(seq)
1def mean(lst):
2 # FASTER!!!!!
3 return sum(lst)/len(lst)
17def variance(lst, avg):
18 var_list = []
19 for num in lst:
20 var_list.append((num - avg)**2)
21 variance = sum(var_list) / len(var_list)
22 return variance

Related snippets