<分区>
我想对一个字符串进行多次 re.sub() 替换,并且每次都用不同 字符串进行替换。
当我有很多子字符串要替换时,这看起来很重复。有人可以建议一个更好的方法吗?
stuff = re.sub('__this__', 'something', stuff)
stuff = re.sub('__This__', 'when', stuff)
stuff = re.sub(' ', 'this', stuff)
stuff = re.sub('.', 'is', stuff)
stuff = re.sub('__', 'different', stuff).capitalize()