Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Remove consecutive duplicates from a string

# Remove the Consecutive Duplicates string word:
# First System:
'''
s = input() #input: BBBBBPPIIAICCODEE
s2 = ""
prev = None
for chr in s:
    if prev != chr:
        s2 += chr
        prev = chr
print(s2)

output: BPIAICODE

'''

# Second System:

# 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 #duplicates #string
ADD COMMENT
Topic
Name
8+2 =