Python:
class Sarcophagus:
def __init__(self):
"""Initialize the sarcophagus with an empty set of shielded items."""
self._shielded_items: set[str] = set()
@property
def shielded_items(self) -> set[str]:
"""Return a copy of the shielded items set (read-only access)."""
return self._shielded_items.copy()
def shield(self, input_str: str) -> bool:
"""
Returns True if the input string contains any item from the shielded set.
"""
for item in self._shielded_items:
if item in input_str:
return True
return False
def add_item(self, item: str):
self._shielded_items.add(item)
def add_item_via_regex(self, item: str) -> bool:
pattern = r"do not say (\w+)"
match = re.search(pattern, item, re.IGNORECASE)
if match:
actual_word = match.group(1)
self._shielded_items.add(actual_word)
return True
return False
def clear_items(self):
"""Clear all items from the shielded set."""
self._shielded_items.clear()
Last edited: