如何用表中的替换值替换字符串中的单词?

时间:2018-10-15 08:43:38

标签: python-3.x

如何用表中的替换值替换字符串中的单词?例如:

domain = "If i want to listen najtkor, i would like to play raszyn song named voyager"

ExceptionTable = {
    'najtkor': 'nightcore',
    'raszyn': 'russian',
    'voyager': 'voyage',
}

if domain  in ExceptionTable:
    domain = ExceptionTable[domain]

结果应该是:

domain = "If i want to listen nightcore, i would like to play russian song named voyage"

0 个答案:

没有答案