average?
Mark McEahern
mark at mceahern.com
Fri Sep 20 13:06:01 EDT 2002
I know I can average a sequence like this:
def average(seq):
return reduce(operator.add(seq) / len(seq))
Yes, I see that will raise ZeroDivisionError if seq == []. Aside from that,
1. Is there anything else dumb about the above?
2. Am I missing a builtin cousin of min, max that would do this for me?
Oops, maybe the answer to 2 is:
import Numeric
Numeric.average(seq)
I guess I just answered my own question.
Cheers,
// m
More information about the Python-list
mailing list