Is there a way to reduce a duplicated characters to specific number, for example if we have this string.
"I liiiiked it, thaaaaaaank you"
Expected output: "I liiiiked it thaaaank you"
so if the duplicated character over 4, for example, it should be reduced to only four characters and if it less than or equal 4 then the word should stays the same.
re.sub(r'a{4,}', 'a', "I liiiiked it, thaaaaaaank you")
will produce'I liiiiked it, thank you'
. – ChrisP Jul 17 '13 at 2:21