SimeonTs

SUPyF2 Text-Pr.-Ex. - 06. Replace Repeating Chars

Oct 27th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. """
  2. Text Processing - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1740#5
  4.  
  5. SUPyF2 Text-Pr.-Ex. - 06. Replace Repeating Chars
  6.  
  7. Problem:
  8. Write a program that reads a string from the console and replaces any sequence of the same letters
  9. with a single corresponding letter.
  10. Examples
  11. Input                       Output
  12. aaaaabbbbbcdddeeeedssaa     abcdedsa
  13. qqqwerqwecccwd              qwerqwecwd
  14. """
  15. past_letter = ""
  16. for i in input():
  17.     if len(past_letter) == 0:
  18.         past_letter = i
  19.     else:
  20.         if i == past_letter[-1]:
  21.             pass
  22.         else:
  23.             past_letter += i
  24. print(past_letter)
Add Comment
Please, Sign In to add comment