Python Exercises: Replace repeated characters with single letters
Remove repeated consecutive chars.
Write a Python program to remove repeated consecutive characters and replace them with single letters and print a updated string.
Sample Data:
("Red Green White") -> "Red Gren White"
("aabbbcdeffff") -> "abcdef"
("Yellowwooddoor") -> "Yelowodor"
Sample Solution-1:
Python Code:
Sample Output:
Original string: Red Green White Remove repeated consecutive characters and replace with the single letters: Red Gren White Original string: aabbbcdeffff Remove repeated consecutive characters and replace with the single letters: abcdef Original string: Yellowwooddoor Remove repeated consecutive characters and replace with the single letters: Yelowodor
Flowchart:

Sample Solution-2:
Python Code:
Sample Output:
Original string: Red Green White Remove repeated consecutive characters and replace with the single letters: Red Gren White Original string: aabbbcdeffff Remove repeated consecutive characters and replace with the single letters: abcdef Original string: Yellowwooddoor Remove repeated consecutive characters and replace with the single letters: Yelowodor
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to compress a string by replacing consecutive duplicate characters with a single occurrence.
- Write a Python program to use regular expressions to remove repeated consecutive characters from a string.
- Write a Python program to iterate through a string and eliminate consecutive duplicates without changing the original order.
- Write a Python program to implement a function that reduces any string with repeating characters to its condensed form.
Go to:
Previous Python Exercise: Extract the name from an Email address.
Next Python Exercise: Two strings contain three letters at the same index.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.