f | import collections | f | import collections |
| | | |
| class SubString(collections.UserString): | | class SubString(collections.UserString): |
| | | |
| def __sub__(self, other): | | def __sub__(self, other): |
| import collections | | import collections |
n | cl = collections.Counter(self) | n | left_counter = collections.Counter(self) |
| cr = collections.Counter(other) | | right_counter = collections.Counter(other) |
| ans_str = '' | | result_str = '' |
| for ch in self.data: | | for char in self: |
| if cl[ch] > 0 and cr[ch] > 0: | | if left_counter[char] > 0 and right_counter[char] > 0: |
| cl[ch] -= 1 | | |
| cr[ch] -= 1 | | left_counter[char] -= 1 |
| | | right_counter[char] -= 1 |
| else: | | else: |
n | ans_str += ch | n | result_str += char |
| del collections | | del collections |
t | return self.__class__(ans_str) | t | return self.__class__(result_str) |
| del collections | | del collections |