[英]How do I only get one word from a dictionary in python?
我正在用python写英语到西班牙语字典。 我让用户输入他们想要翻译的内容,然后我的程序读取我创建的文件并打印该单词的西班牙语等效词。 目前,它仅打印整个词典。 这可能很容易,但是我对此并不陌生,似乎无法弄清楚。 谢谢
`# coding: utf-8
s=(input("please enter a word to be translated: "))
file=open("dictionary.txt")
engtospa={}
for s in file:
aList=s.split()
b=aList[0:]
engtospa[s]=aList[1:0]
print(engtospa)
`
您需要指定要翻译的密钥。
# coding: utf-8
s=(input("please enter a word to be translated: "))
file=open("dictionary.txt")
engtospa={}
for s in file:
aList=s.split()
b=aList[0:]
engtospa[s]=aList[1:0]
print(engtospa) # <-- your code
print(engtospa[s]) # <-- expected
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.