Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

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
'''
Comment

PREVIOUS NEXT
Code Example
Python :: file handling in python append byte 
Python :: Syntax of Opening a File in python 
Python :: Reverse an string Using Loop in Python 
Python :: python class example 
Python :: add a constant to a list python 
Python :: www.pd.date_range 
Python :: pandas read columns as list 
Python :: convert image to binary python 
Python :: lower and upper case user input python 
Python :: librosa python 
Python :: dynamically create python dictionary 
Python :: blender change text during animation 
Python :: python gui framework 
Python :: python check if string contains symbols 
Python :: Removing Elements from Python Dictionary Using clear() method 
Python :: python compiler online 
Python :: a function to create a null matrix in python 
Python :: .translate python 
Python :: division in python 
Python :: delete from table django 
Python :: Python NumPy tile Function Example 
Python :: Encrypting a message in Python 
Python :: python - login 
Python :: python poetry 
Python :: sample hyperparameter tuning with grid search cv 
Python :: len dictionary python 
Python :: Exception in thread 
Python :: create django object 
Python :: List Get a Element 
Python :: how to run python on ios 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =