Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

consecutive duplicate string remove

# 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: #consecutive #duplicate #string #remove
ADD COMMENT
Topic
Name
1+9 =