In this program, we will take a string as input and remove all consecutive duplicates from a string
Steps to solve the program
- Take a string as input and create an empty list.
- From itertools import groupby for removing all consecutive duplicates from the given string.
- After removing consecutive duplicate characters add them to the list.
- Join the list ti convert it into a string using join().
- Print the output.
#Input string
str1= "xxxxyy"
list1 = []
#Importing group
from itertools import groupby
for (key,group) in groupby(str1):
list1.append(key)
#Printing output
print("".join(list1))
Output :
xy