from collections.abc import MutableSet __author__ = 'Horacio Hoyos' __copyright__ = 'Copyright , Kinori Technologies' class MofSet(MutableSet): def __init__(self, iterable): self._set = set(iterable) def __contains__(self, item): return item in self._set def __iter__(self): return self._set.__iter__() def __len__(self): return len(self._set) def add(self, item): self._set.add(item) def discard(self, item): self._set.discard(item) def intersection(self, other): return self._set.intersection(other) # Tests based on Python's test_set.py def call_and(): word = 'simsalabim' otherword = 'madagascar' myset = MofSet(word) i = myset.intersection(otherword) assert myset & set(otherword) == i assert myset & frozenset(otherword) == i try: myset & otherword except TypeError: pass else: print("s&t did not screen-out general iterables") if __name__ == '__main__': call_and()