I saw plenty of suggestions to remove consecutively repeated letters in a sentence either using re (regex) or .join in python, but I want to have exception for special words.
E.g.:
I want this sentence > sentence = 'hello, join this meeting heere using thiis lllink'
to be like this > 'hello, join this meeting here using this link'
knowing that I have this list of words to keep and ignore repetitive letters check: keepWord = ['Hello','meeting']
The two scripts I found useful are:
Using .join:
import itertools sentence = ''.join(c[0] for c in itertools.groupby(sentence))Using regex:
import re sentence = re.compile(r'(.)\1{1,}').sub(r'\1', sentence)
I have a solution, but I think there's a more compacted and efficient one. My solution for now is:
import itertools
sentence = 'hello, join this meeting heere using thiis lllink'
keepWord = ['hello','meeting']
new_sentence = ''
for word in sentence.split():
if word not in keepWord:
new_word = ''.join(c[0] for c in itertools.groupby(word))
new_sentence = sentence +" " + new_word
else:
new_sentence = sentence +" " + word
Any suggestions?