| t | import collections | t | import collections |
| | | |
| class SubString(collections.UserString): | | class SubString(collections.UserString): |
| | | |
| def __sub__(self, other): | | def __sub__(self, other): |
| from collections import Counter | | from collections import Counter |
| other_counter = Counter(other) | | other_counter = Counter(other) |
| result_chars = [] | | result_chars = [] |
| for char in self.data: | | for char in self.data: |
| if other_counter.get(char, 0) > 0: | | if other_counter.get(char, 0) > 0: |
| other_counter[char] -= 1 | | other_counter[char] -= 1 |
| else: | | else: |
| result_chars.append(char) | | result_chars.append(char) |
| return SubString(''.join(result_chars)) | | return SubString(''.join(result_chars)) |
| del collections | | del collections |