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:
Python Code Editor:
Previous Python Exercise: Extract the name from an Email address.
Next Python Exercise: Two strings contain three letters at the same index.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics