update from O'Reilly repo

This commit is contained in:
Luciano Ramalho
2021-03-22 12:24:21 -03:00
parent e1cd63aa04
commit 2f8bf06270
28 changed files with 470 additions and 125 deletions

14
15-type-hints/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()