simeonshopov

Replace Repeating Chars

Feb 11th, 2020
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. # text = [x for x in input()]
  2. #
  3. # for i in range(len(text) - 3, - 1, -1):
  4. #     previous = text[i + 1]
  5. #     current = text[i]
  6. #     if previous ==  current:
  7. #         text.remove(text[i])
  8. #
  9. # print(''.join(text))
  10.  
  11.  
  12. text = [x for x in input()]
  13.  
  14. for i in range(len(text) - 2, -1, -1):
  15.     if text[i] == text[i + 1]:
  16.         text.remove(text[i])
  17.  
  18. print(''.join(text))
  19.  
  20. text = [x for x in input()]
  21.  
  22. for i in range(len(text) - 2, -1, -1):
  23.     # if i == 0 and text[i] != text[i + 1]:
  24.     #     break
  25.     if text[i] == text[i + 1]:
  26.         text.pop(i)
  27.  
  28. print(''.join(text))
Advertisement
Add Comment
Please, Sign In to add comment