def moving_av(l, n):
    """Take a list, l, and return the average of its last n elements.
    """
observations = len(l[-n:])
return sum(l[-n:]) / float(observations)
Deciding and implementing a trending algorithm in Django