Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

remove consecutive duplicate string in python

# Remove the Consecutive Duplicates string word:
# First System:

#Example input: BBBBBPPIIAICCODEE

s = input() 
s2 = ""
prev = None
for chr in s:
    if prev != chr:
        s2 += chr
        prev = chr
print(s2)

output: BPIAICODE



# Second System:

# Example input: SSSWWWIIFTPPYTHOOOOOOOOONNNNNNNNN
'''
def removeConsecutiveDuplicates(s):
    if len(s) < 2:
        return s
    if s[0] != s[1]:
        return s[0] + removeConsecutiveDuplicates(s[1:])
    return removeConsecutiveDuplicates(s[1:])

# This code is contributed:
s1 = input()
print(removeConsecutiveDuplicates(s1))
# output: SWIFTPYTHON
'''
 
PREVIOUS NEXT
Tagged: #remove #consecutive #duplicate #string #python
ADD COMMENT
Topic
Name
3+7 =