I have a program where I\'m keeping track of the success of various things using collections.Counter
— each success of a thing increments the corr
Another variant with iteration:
import collections
from collections import Counter
import random
class CounterElementsRandomAccess(collections.Sequence):
def __init__(self, counter):
self._counter = counter
def __len__(self):
return sum(self._counter.values())
def __getitem__(self, item):
for i, el in enumerate(self._counter.elements()):
if i == item:
return el
scoreboard = Counter('AAAASDFQWERQWEQWREAAAAABBBBCCDDVBSDF')
score_elements = CounterElementsRandomAccess(scoreboard)
for i in range(10):
print random.choice(score_elements)