本文介绍了使用字典翻译短语? (Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用我的词典将短语粗略地翻译成英语,但是我不确定如何做到.

I have to do a rough translation of the phrase into English using my dictionary, but I'm not sure how.

c1 = "befreit"
c2 = "baeche"
c3 = "eise"
c4 = "sind"
c5 = "strom"
c6 = "und"
c7 = "vom"

mydict = {c1:"liberated", c2:"brooks", c3:"ice", c4:"are", c5:"river", c6:"and", c7:"from"}

print(mydict.keys())
print(mydict.values())

phrase = "vom eise befreit sind strom und baeche"
print(phrase)

phrase.split()
for x in phrase:
    #something goes here

推荐答案

将这两者都存储为字典中的键和值:

store both in your dict as keys an values:

 mydict = {"befreit":"liberated", "baeche":"brooks", "eise":"ice", "sind":"are", "strom":"river", "und":"and", "vom":"from"}


phrase = "vom eise befreit sind strom und baeche"
print(" ".join([mydict[w] for w in phrase.split()]))
from ice liberated are river and brooks

这篇关于使用字典翻译短语? (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 16:09