Skip to content Skip to sidebar Skip to footer

How To Remove Any Unicode Repeating Letter?

In english, sometimes you have repeating letter like this : hello my hero hhhhhhhhhhh that's for h, but I want to remove all kinds of letters repeating like this 2 or more times an

Solution 1:

try this:

from itertools import groupby

defremove_dups(s):
    replace_with = ' 'return''.join([x ifsum(1for i in y)<2else replace_with for x,y in groupby(s)])

Solution 2:

any duplicated character

import re
re.sub(r'(.)\1+', ' ', 'مرحبا هههههههههه')
# 'مرحبا  '

only letter characters

import regex
regex.sub(r'(\pL)\1+', ' ', 'مرحبا هههههههههه')

Post a Comment for "How To Remove Any Unicode Repeating Letter?"