-2

I have a list of data e.g. A = [1,2,3,10,4,3.5,16,11,19,6,13] Now I want to find the mean value of this data set when entry value is less than 10. How can I do it in Python?

Bikash
  • 147
  • 2
  • 8

2 Answers2

2

You can use statistics.mean

from statistics import mean

a = [1,2,3,4,5,6,7,8,9,10]
print(mean(a)) # 5.5
Guy
  • 46,488
  • 10
  • 44
  • 88
2

You can get sub list using list slicing - A[start:stop:step]

python3.*:

>>> sum(A[:10]) / 10    # 10:is length of your sublist
5.5

python2.*:

>>> from __future__ import division   # to get float division like python3
>>> sum(A[:10]) / 10    # 10:is length of your sublist
5.5
anonymous
  • 189
  • 1
  • 10
  • I'm going to strongly suggest removing the Python 2 answer, since Python 2 is no longer supported, and should (thus) not be (promoted to be) used anymore. – 9769953 Jan 30 '20 at 08:58