ch15: draft examples
This commit is contained in:
14
15-more-types/erp.py
Normal file
14
15-more-types/erp.py
Normal 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()
|
||||
Reference in New Issue
Block a user