Finding the average of a list

前端 未结 23 1831
抹茶落季
抹茶落季 2020-11-22 11:07

I have to find the average of a list in Python. This is my code so far

l = [15, 18, 2, 36, 12, 78, 5, 6, 9]
print reduce(lambda x, y: x + y, l)
23条回答
  •  醉梦人生
    2020-11-22 12:01

    If you wanted to get more than just the mean (aka average) you might check out scipy stats

    from scipy import stats
    l = [15, 18, 2, 36, 12, 78, 5, 6, 9]
    print(stats.describe(l))
    
    # DescribeResult(nobs=9, minmax=(2, 78), mean=20.11111111111111, 
    # variance=572.3611111111111, skewness=1.7791785448425341, 
    # kurtosis=1.9422716419666397)
    

提交回复
热议问题