のリストに含まれている場合、私は次の文字列を持っている文字列内の単語を置き換えます。出力はは、それが言葉
'何が本当に起こっていない、月1999年に月1999年と同じ'
よう
for month in month_set: sentence = s.replace(month, 'date') print(sentence)
になりますが、それは次のように返さ:
in may 1999, nothing really happened, same as in june 1999 in date 1999, nothing really happened, same as in june 1999 in may 1999, nothing really happened, same as in date 1999
上記の場合、私はそれを遅くする大きな文字列に適用する必要があります。
速度はその後、正規表現の問題である場合おそらく最も速い方法でしょう – chasmani