9.6.2009

Weighted Average in python

  def WeightedAverage(items, value, weight):
    numerator = sum(value(i) * weight(i) for i in items)
    divisor =  sum(weight(i) for i in items)
    return (numerator / divisor) if divisor != 0 else None




comments powered by Disqus