import re
# Only repeated numbers
answer = re.sub(r'(\d)\1+', r'\1', '12233322155552')
# Any repeated character
answer = re.sub(r'(.)\1+', r'\1', '12233322155552')
More Related Contents:
- How do I check if there are duplicates in a flat list?
- How can I remove duplicate words in a string with Python?
- Unable to use convert strings into integers for a for loop
- How do I execute a string containing Python code in Python?
- How to format a floating number to fixed width in Python
- Split a string by a delimiter in python
- Replacing instances of a character in a string
- Count number of occurrences of a substring in a string
- How to check if the string is empty?
- How do I trim whitespace?
- Finding all possible permutations of a given string in python
- Converting from a string to boolean in Python?
- Splitting a string into words and punctuation
- Suppress the u’prefix indicating unicode’ in python strings
- Convert columns to string in Pandas
- Understanding string reversal via slicing
- byte string vs. unicode string. Python
- Difference between using commas, concatenation, and string formatters in Python
- how to do bitwise exclusive or of two strings in python?
- Mutable strings in Python
- How do you check in python whether a string contains only numbers?
- Check presence of vowels in a string
- Does R have function startswith or endswith like python? [closed]
- Remove Sub String by using Python
- How to split a Python string on new line characters [duplicate]
- How to Print “Pretty” String Output in Python
- How can I check if a string has a numeric value in it in Python? [duplicate]
- get python dictionary from string containing key value pairs
- Mutable and Immutable Strings in python
- Detect whether a Python string is a number or a letter [duplicate]