SubString/warnachinka
SubString/sver
t1class SubString:t1class SubString:
2    def __init__(self, s):2    def __init__(self, s):
3        self.s = str(s)3        self.s = str(s)
44
5    def __sub__(self, other):5    def __sub__(self, other):
6        res = ''6        res = ''
7        f = other.s if isinstance(other, SubString) else other7        f = other.s if isinstance(other, SubString) else other
8        tosub = {}8        tosub = {}
9        for a in f:9        for a in f:
10            if a in tosub:10            if a in tosub:
11                tosub[a] += 111                tosub[a] += 1
12            else:12            else:
13                tosub[a] = 113                tosub[a] = 1
14        for ch in self.s:14        for ch in self.s:
15            if ch in tosub and tosub[ch] > 0:15            if ch in tosub and tosub[ch] > 0:
16                tosub[ch] -= 116                tosub[ch] -= 1
17            else:17            else:
18                res += ch18                res += ch
19        return SubString(res)19        return SubString(res)
2020
21    def __add__(self, other):21    def __add__(self, other):
22        f = other.s if isinstance(other, SubString) else other22        f = other.s if isinstance(other, SubString) else other
23        return SubString(self.s + f)23        return SubString(self.s + f)
2424
25    def __radd__(self, other):25    def __radd__(self, other):
26        f = other.s if isinstance(other, SubString) else other26        f = other.s if isinstance(other, SubString) else other
27        return SubString(f + self.s)27        return SubString(f + self.s)
2828
29    def __mul__(self, other):29    def __mul__(self, other):
30        return SubString(self.s * other)30        return SubString(self.s * other)
3131
32    def __getitem__(self, item):32    def __getitem__(self, item):
33        return SubString(self.s[item])33        return SubString(self.s[item])
3434
35    def __repr__(self):35    def __repr__(self):
36        return self.s36        return self.s
3737
38    def __str__(self):38    def __str__(self):
39        return self.s39        return self.s
4040
41    def __contains__(self, item):41    def __contains__(self, item):
42        f = item.s if isinstance(item, SubString) else item42        f = item.s if isinstance(item, SubString) else item
43        return self.s.__contains__(f)43        return self.s.__contains__(f)
4444
45    def __eq__(self, other):45    def __eq__(self, other):
46        f = other.s if isinstance(other, SubString) else other46        f = other.s if isinstance(other, SubString) else other
47        return self.s.__eq__(f)47        return self.s.__eq__(f)
4848
49    def __gt__(self, other):49    def __gt__(self, other):
50        f = other.s if isinstance(other, SubString) else other50        f = other.s if isinstance(other, SubString) else other
51        return self.s.__gt__(f)51        return self.s.__gt__(f)
5252
53    def __ge__(self, other):53    def __ge__(self, other):
54        f = other.s if isinstance(other, SubString) else other54        f = other.s if isinstance(other, SubString) else other
55        return self.s.__ge__(f)55        return self.s.__ge__(f)
5656
57    def __len__(self):57    def __len__(self):
58        return self.s.__len__()58        return self.s.__len__()
5959
60    def __getattr__(self, name):60    def __getattr__(self, name):
61        attr = getattr(self.s, name)61        attr = getattr(self.s, name)
62        if not callable(attr):62        if not callable(attr):
63            return attr63            return attr
6464
65        def mapper(a):65        def mapper(a):
66            if isinstance(a, SubString):66            if isinstance(a, SubString):
67                return a.s67                return a.s
68            return a68            return a
6969
70        def method(*args):70        def method(*args):
71            if len(args) > 0:71            if len(args) > 0:
72                args = tuple(map(mapper, args))72                args = tuple(map(mapper, args))
73                return SubString(attr(*args))73                return SubString(attr(*args))
74            return SubString(attr())74            return SubString(attr())
7575
76        return method76        return method
7777
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op