X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=grab_bag.py;h=798ebcfb154b58c3fdbf9588bcc01bc4b69d140a;hb=e4dca16bbd329afdb587e8488767d88e17777254;hp=49582fb16e6fafe2688d952abccdfe6d098fff7b;hpb=4b1f3d8a8b278ca6d62f461ea80c8ea21080c301;p=kiosk.git diff --git a/grab_bag.py b/grab_bag.py index 49582fb..798ebcf 100644 --- a/grab_bag.py +++ b/grab_bag.py @@ -1,29 +1,34 @@ +#!/usr/bin/env python3 + import random +from typing import Iterable, List, Optional, Set + class grab_bag(object): - def __init__(self): - self.contents = set() + def __init__(self) -> None: + self.contents: Set[str] = set() - def clear(self): + def clear(self) -> None: self.contents.clear() - def add(self, item): + def add(self, item: str) -> None: if item not in self.contents: self.contents.add(item) - def add_all(self, collection): + def add_all(self, collection: Iterable[str]) -> None: for x in collection: self.add(x) - def subset(self, count): + def subset(self, count: int) -> Optional[List[str]]: if len(self.contents) < count: return None subset = random.sample(self.contents, count) return subset - def size(self): + def size(self) -> int: return len(self.contents) -#x = grab_bag() -#x.add_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) -#print x.subset(3) + +# x = grab_bag() +# x.add_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) +# print x.subset(3)