Возможно не точно выразился.
s = str(input()) code = False for i in range(len(s)): try: if s[i]==s[i-1]: s = s.replace(s[i]*2,'') i-=2 print(s) continue except: pass print(s)
s = str(input()) code = False for i in range(len(s)): try: if s[i]==s[i-1]: s = s.replace(s[i]*2,'') i-=2 print(s) continue except: pass print(s)
MEOWда, как сказал предыдущий участник - если вы будете играться со своим итератором.
Возможна ли там реализация того, чего хочу?
class MyIter: def __init__(self, end): self.current = -1 self.end = end def __iter__(self): return self def __next__(self): if self.current < -1: raise StopIteration() return self.next() def next(self): self.current += 1 if self.current >= self.end: raise StopIteration() return self.current def previous(self): self.current -= 2 return self.current def test_1(): assert [x for x in MyIter(3)] == [0, 1, 2] def test_2(): flag = False l = [] my_iter = MyIter(5) for value in my_iter: if not flag and value == 3: flag = not flag my_iter.previous() l.append(value) assert l == [0, 1, 2, 3, 2, 3, 4] def test_3(): l = [] my_iter = MyIter(3) for value in my_iter: my_iter.previous() l.append(value) assert l == [0]