Skip to content

Commit c490339

Browse files
committed
committed from zkp
1 parent 117bd23 commit c490339

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

FluentPython/BingoCage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import random
2+
3+
4+
class BingoCage:
5+
def __init__(self, items):
6+
self._items = list(items)
7+
random.shuffle(self._items)
8+
9+
def pick(self):
10+
try:
11+
return self._items.pop()
12+
except IndexError:
13+
raise LookupError('pick from empty BingoCage')
14+
15+
def __call__(self):
16+
return self.pick()
17+
18+
if __name__ == '__main__':
19+
bingo = BingoCage(range(10))
20+
callable(bingo)
21+
print(bingo(), bingo.pick())
22+

0 commit comments

Comments
 (0)