0
english_list = ["fire","apple","morning","river","wind"]
spanish_list = ["fuego","manzana","mañana","río","viento"]
english_to_spanish = dict(zip(english_list, spanish_list))
spanish_to_english = dict(zip(spanish_list, english_list))
def translate(word):
translation = english_to_spanish.get(word)
if translation:
return translation
translation = spanish_to_english.get(word)
if translation:
return translation
raise Exception('Word {0} does not exists'.format(word))
print("Welcome to the English <--> Spanish Dictionary")
while True:
word = input("> ")
if word == 'show':
wordlist = input("Would you like to see the English or Spanish wordlist?")
if wordlist == 'english':
print(english_list)
elif wordlist == 'spanish':
print(spanish_list)
else:
try:
print(translate(word))
except Exception as exeception:
print ("That wasn't a option")
这是我的代码,我想导入一个字典(我有),但我不知道如何做到这一点,我是相当新的编码,真的需要一些帮助,这是一个学校的任务,我真的需要无缝的帮助,任何帮助将大量赞赏!导入字典
什么是要导入的词典的*格式*? –
通过导入,你的意思是说你有一个带有单词对的文件(英文与西班牙文配对)?或者如你的例子所暗示的,你有两个单独的文件,包含英文单词和西班牙文单词列表? –