Created
February 8, 2020 03:34
-
-
Save luisenriquecorona/42cddfc00cfdfbc00c93e980b7b1b907 to your computer and use it in GitHub Desktop.
A BingoCage does one thing: picks items from a shuffled list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class BingoCage: | |
def __init__(self, items): | |
self._items = list(items) | |
random.shuffle(self._items) | |
def pick(self): | |
try: | |
return self._items.pop() | |
except IndexError: | |
raise LookupError('pick from empty BingoCage') | |
def __call__(self): | |
return self.pick() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment