Skip to content

Latest commit

 

History

History
20 lines (15 loc) · 630 Bytes

replace-multiple-terms-from-a-string.md

File metadata and controls

20 lines (15 loc) · 630 Bytes

Replace multiple terms from a string

Replacing multiple terms in a string.

def replaceMultiple(mainString, toBeReplaces, newString):
    # Iterate over the strings to be replaced
    for elem in toBeReplaces:
        # Check if string is in the main string
        if elem in mainString:
            # Replace the string
            mainString = mainString.replace(elem, newString)

    return mainString

wordsToRemove = ['via', 'test', 'good']
text = replaceMultiple(originalText, wordsToRemove, '')

Got it from here