More fuckery with indented sublists in gkeep and with the countdown line.
[kiosk.git] / grab_bag.py
1 import random
2
3 class grab_bag(object):
4     def __init__(self):
5         self.contents = set()
6
7     def clear(self):
8         self.contents.clear()
9
10     def add(self, item):
11         if item not in self.contents:
12             self.contents.add(item)
13
14     def add_all(self, collection):
15         for x in collection:
16             self.add(x)
17
18     def subset(self, count):
19         if len(self.contents) < count:
20             return None
21         subset = random.sample(self.contents, count)
22         return subset
23
24     def size(self):
25         return len(self.contents)
26
27 #x = grab_bag()
28 #x.add_all([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
29 #print x.subset(3)