すべてのキーが 3 文字の長さの辞書があります。threeLetterDict={'abc': 'foo', 'def': 'bar', 'ghi': 'ha' ...}
次に、文abcdefghi
をに翻訳する必要がありfoobarha
ます。で以下の方法を試していますがre.sub
、辞書を入れる方法がわかりません:
p = re.compile('.{3}') # match every three letters
re.sub(p,'how to put dictionary here?', "abcdefghi")
ありがとう!(入力長が 3 の倍数かどうかを確認する必要はありません)