Remove all consecutive duplicates from a string.

In this program, we will take a string as input and remove all consecutive duplicates from a string

Steps to solve the program
  1. Take a string as input and create an empty list.
  2. From itertools import groupby for removing all consecutive duplicates from the given string.
  3. After removing consecutive duplicate characters add them to the list.
  4. Join the list ti convert it into a string using join().
  5. 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
				
			

find the maximum length of consecutive 0’s in a given binary string

Create a string that consists of multi-time occurring characters

Leave a Comment