I'm looking at a statement that looks like this:
def fn(somelongstring):
shorterstring = somelongstring.replace('very, ','').replace('long ', '')
fn('some very, very, very, long string')
what's the most efficient method for performing this kind of operation in Python?
Some notes:
- The list of replace calls is quite long, but fixed and known in advance
- The long string is an argument to the function, and can get massive; it includes repetitions of the substrings
- My intuition is that deletion has the opportunity to use different, faster, algorithms from replace
- The chained replace calls are probably each iterating over the string. There has to be a way to do this without all those repeated iterations.