Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

remove consecutive duplicates python

def remove_consecutive_duplicates(_list: list):
    preprocessed_list = []
    for x in itertools.groupby(_list):
        preprocessed_list.append(x[0])

    return preprocessed_list
Comment

python remove consecutive duplicates

no_consecutive_duplicates = [x[0] for x in itertools.groupby(my_list)]
Comment

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
Comment

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

PREVIOUS NEXT
Code Example
Python :: get key(s) for min value in dict python 
Python :: how to make your own range function in python 
Python :: python string to list new line 
Python :: rolling window pandas 
Python :: update python 3.9 
Python :: how to correlation with axis in pandas 
Python :: get channle from id discord.py 
Python :: find total no of true in a list in python 
Python :: access myultiple dict values with list pythojn 
Python :: connect mongodb with python 
Python :: typing pandas dataframe 
Python :: python dict sortieren 
Python :: select rows in python 
Python :: fastapi oauth2 
Python :: functions python examples 
Python :: how to install package offline 
Python :: histogram seaborn python 
Python :: to_cvs python 
Python :: python convert list of lists to array 
Python :: python check if string contains substring 
Python :: how to access http page in pythion 
Python :: how to get the realpath with python 
Python :: python discord embed link 
Python :: deep clone 2d list python 
Python :: pandas astype str still object 
Python :: text cleaning python 
Python :: plt tickpad 
Python :: swap two columns python 
Python :: how to run flask in port 80 
Python :: numpy multiply element wise 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =