24 lines
545 B
Python
24 lines
545 B
Python
import abc
|
|
|
|
class Tombola(abc.ABC): # <1>
|
|
|
|
@abc.abstractmethod
|
|
def load(self, iterable): # <2>
|
|
"""Add items from an iterable."""
|
|
|
|
@abc.abstractmethod
|
|
def pick(self): # <3>
|
|
"""Remove item at random, returning it.
|
|
|
|
This method should raise `LookupError` when the instance is empty.
|
|
"""
|
|
|
|
def loaded(self): # <4>
|
|
try:
|
|
item = self.pick()
|
|
except LookupError:
|
|
return False
|
|
else:
|
|
self.load([item]) # put it back
|
|
return True
|