Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

python - 查找列表的平均值(Finding the average of a list)

I have to find the average of a list in Python.

(我必须在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)

I've got it so it adds together the values in the list, but I don't know how to make it divide into them?

(我已经知道了,所以它可以将列表中的值相加,但是我不知道如何将其划分为它们?)

  ask by Carla Dessi translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
l = [15, 18, 2, 36, 12, 78, 5, 6, 9]
sum(l) / len(l)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...