Slide 12
Slide 12 text
# The `elements` method gives you an iterator
# that yields a `key` for each`count`
>>> colors = ['red', 'blue', 'yellow']
>>> c = Counter(colors)
>>> c
Counter({'blue': 1, 'yellow': 1, 'red': 1})
>>> c['red'] += 2 # Three 'red's
>>> c['blue'] += 1 # Two 'blues's
>>> c
Counter({'red': 3, 'blue': 2, 'yellow': 1})
>>> list(c.elements())
['blue', 'blue', 'yellow', 'red', 'red', 'red']
Tuesday, February 5, 13