I always supposed avg
is omitted from the builtins/stdlib because it is as simple as
sum(L)/len(L) # L is some list
and any caveats would be addressed in caller code for local usage already.
Notable caveats:
non-float result: in python2, 9/4 is 2. to resolve, use float(sum(L))/len(L)
or from __future__ import division
division by zero: the list may be empty. to resolve:
if not L:
raise WhateverYouWantError("foo")
avg = float(sum(L))/len(L)