[Solved] Removing all occurrences of any characters in the word ‘dust’ in the string [closed]


Use a regular expression.

import re

result = re.sub(r'[dust]', '', string)

The regexp [dust] matches any of those characters, and all the matches are replaced with an empty string.

If you want to remove only the whole word dust, with possible repetitions of the letters, the regexp would be r'd+u+s+t+'.

If only u can be repeated, use r'du+st'.

4

solved Removing all occurrences of any characters in the word ‘dust’ in the string [closed]