def __init__(self, weights): self.totals = list(itertools.accumulate(weights)) self.total = self.totals[-1]