【发布时间】:2017-11-13 03:57:51
【问题描述】:
所以我开始研究这个小翻译程序,它可以通过输入将英语翻译成德语。但是,当我输入多个单词时,我会得到我输入的单词,然后是正确的翻译。
这是我目前所拥有的:
data = [input()]
dictionary = {'i':'ich', 'am':'bin', 'a':'ein', 'student':'schueler', 'of
the':'der', 'german':'deutschen', 'language': 'sprache'}
from itertools import takewhile
def find_suffix(s):
return ''.join(takewhile(str.isalpha, s[::-1]))[::-1]
for d in data:
sfx = find_suffix(d)
print (d.replace(sfx, dictionary.get(sfx, sfx)))
我正在尝试获得以下输出:
"i am a student of the german sprache"
相对于:
"ich bin ein schueler der deutschen spracher"
我对 python 很陌生,所以任何帮助都将不胜感激
【问题讨论】: