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 | left_counter = collections.Counter(self) | n | cl = collections.Counter(self) |
| right_counter = collections.Counter(other) | | cr = collections.Counter(other) |
| result_str = '' | | ans_str = '' |
| for char in self: | | for ch in self.data: |
| if left_counter[char] > 0 and right_counter[char] > 0: | | if cl[ch] > 0 and cr[ch] > 0: |
| | | cl[ch] -= 1 |
| left_counter[char] -= 1 | | cr[ch] -= 1 |
| right_counter[char] -= 1 | | |
| else: | | else: |
n | result_str += char | n | ans_str += ch |
| del collections | | del collections |
t | return self.__class__(result_str) | t | return self.__class__(ans_str) |
| del collections | | del collections |