Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Eliminate consecutive duplicates from a string in python

# 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: #Eliminate #consecutive #duplicates #string #python
ADD COMMENT
Topic
Name
3+3 =