短语的双向翻译

2024-10-04 11:26:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在英语学习上有困难。 我只能把它从英语翻译成英语。 我想要的是如果这个词是英语翻译成Tuccin, 如果单词是Tuccin,请翻译成英语完整短语。 最后,如果有任何输入字没有存储,我想要它 把同一个词印在自己的地方,这样就可以证明 没什么好翻译的

#Translator.py
Tuc={"i":["o"],"love":["wau"],"you":["uo"],"me":["ye"],"my":["yem"],
     "mine":["yeme"],"are":["sia"]}
phrase=True
reverseLookup = False

while True:
    reverseLookup = False
    translation = str(raw_input("Enter content for translation.\n").lower())
    input_list = translation.split()

#English to Tuccin
if phrase ==True:
    print "*English Detected!"

    for word in input_list:
        if word in Tuc:
            print ("".join(Tuc[word]))
        else:
            reverseLookup = True

#Tuccin to english
elif phrase == True and reverseLookup == True:
    print "*Tuccin Detected!"
    input_list = translation.split()
    for k, v in Tuc.iteritems():
        if translation in v:
            print k

        else:
            print "Word Not Stored!"
            reverseLookup = False
            print word

Tags: infalsetrueforinputiftranslationlist
1条回答
网友
1楼 · 发布于 2024-10-04 11:26:09

Thisstack answer演示如何快速反转简单字典。所以,在你的情况下,你要做的是:

Eng = {t[0]: [e] for t, e in Tuc.items()}

用这本字典的方法和你用Tuc字典的方法一样

如果您的Tuc字典没有冗余的列表作为值,则会更容易:

Tuc = {'me': 'ye', 'love': 'wau', 'i': 'o', 'mine': 'yeme', 'are': 'sia', 'you': 'uo', 'my': 'yem'}
Eng = {t: e for t, e in Tuc.items()}

相关问题 更多 >