updated contents from Atlas repo
This commit is contained in:
30
functions/bingo.py
Normal file
30
functions/bingo.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
# BEGIN BINGO_DEMO
|
||||
|
||||
>>> bingo = BingoCage(range(3))
|
||||
>>> bingo()
|
||||
2
|
||||
>>> bingo()
|
||||
0
|
||||
>>> callable(bingo)
|
||||
True
|
||||
# END BINGO_DEMO
|
||||
|
||||
"""
|
||||
|
||||
# BEGIN BINGO
|
||||
|
||||
import random
|
||||
|
||||
class BingoCage:
|
||||
|
||||
def __init__(self, items):
|
||||
self._items = list(items) # <1>
|
||||
random.shuffle(self._items) # <2>
|
||||
|
||||
def __call__(self):
|
||||
if not self._items: # <3>
|
||||
raise IndexError('pop from empty BingoCage')
|
||||
return self._items.pop()
|
||||
|
||||
# END BINGO
|
||||
Reference in New Issue
Block a user