ch15: draft examples

This commit is contained in:
Luciano Ramalho
2021-05-20 22:58:05 -03:00
parent 5312d4f824
commit 1689eec623
19 changed files with 501 additions and 36 deletions

14
15-more-types/erp.py Normal file
View File

@@ -0,0 +1,14 @@
import random
from typing import TypeVar, Generic, List, Iterable
T = TypeVar('T')
class EnterpriserRandomPopper(Generic[T]):
def __init__(self, items: Iterable[T]) -> None:
self._items: List[T] = list(items)
random.shuffle(self._items)
def pop_random(self) -> T:
return self._items.pop()