similar function to php's str_replace in python?

python

Solution

I believe the answer is no.

I would specify your search/replace strings in a list, and the iterate over it:

edits = [(search0, replace0), (search1, replace1), (search2, replace2)] # etc.
for search, replace in edits:
    s = s.replace(search, replace)

Even if python did have a `str_replace`-style function, I think I would still separate out my search/replace strings as a list, so really this is only taking one extra line of code.

Finally, this is a programming language after all. If it doesn't supply the function you want, you can always define it yourself.

Problem

is there a similar function in python that takes search(array) and replace(array) as a parameter? Then takes a value from each array and uses them to do search and replace on subject(string). I know I can achieve this using for loops, but just looking more elegant way.

Original source

Related problems