使用字典和类似这个字符串的东西(或从文件中读取,或其他):
rep = {'January':'Febryary', 'September':'november', 'monthly':'weekly'}
s = """One reason the Fed is likely to wait until early 2014 to begin easing back on stimulus efforts is that policy makers there simply will not know if the labor market is gaining or losing strength before then. Not until December will the monthly jobs survey be free of the shutdown static, and that report does not come out until early January.
The September jobs report was disappointing, with the economy adding 148,000 new jobs instead of the expected 185,000, but stocks rose on anticipation that Fed stimulus efforts would continue well into 2014."""
然后,您可以使用此单线:
result = reduce(lambda x, y: x.replace(*y), rep.iteritems(), s)
或者使用(在我看来更有效的)正则表达式:
import re
rep = dict((re.escape(k), v) for k, v in rep.iteritems()) # makes sure things wont screw up
pattern = re.compile("|".join(rep.keys())) # create the pattern
result = pattern.sub(lambda m: rep[re.escape(m.group(0))], s)
但实际上,如果你正在处理这样的事情,你应该看看nltk (Natural Language Toolkit)