Q:

Write a Python program to remove all consecutive duplicates of a given string

0

Write a Python program to remove all consecutive duplicates of a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

from itertools import groupby 
def remove_all_consecutive(str1): 
	result_str = [] 
	for (key,group) in groupby(str1): 
		result_str.append(key) 

	return ''.join(result_str)
	
str1 = 'xxxxxyyyyy'
print("Original string:" + str1)
print("After removing consecutive duplicates: " + str1)
print(remove_all_consecutive(str1))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now