5 from typing import Iterable, List, Optional, Set
8 logger = logging.getLogger(__name__)
11 class grab_bag(object):
12 def __init__(self) -> None:
13 self.contents: Set[str] = set()
15 def clear(self) -> None:
18 def add(self, item: str) -> None:
19 if item not in self.contents:
20 self.contents.add(item)
22 def add_all(self, collection: Iterable[str]) -> None:
26 def subset(self, count: int) -> Optional[List[str]]:
27 if len(self.contents) < count:
29 return random.sample(self.contents, count)
31 def size(self) -> int:
32 return len(self.contents)
36 # x.add_all(["oneA", "two", "three", "oneB", "four", "five", "oneC", "oneD"])