Michael Jones
Michael Jones

Reputation: 77

How do I only get one word from a dictionary in python?

I'm writing an English to Spanish dictionary in python. I have the user input what they want translated and the my program reads a file I created and print the Spanish equivalent of the word. Currently it just print the whole dictionary. This is probably easy but I am new to this and can't seem to figure it out. Thanks

`# 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)

`  

Upvotes: 0

Views: 531

Answers (1)

OShadmon
OShadmon

Reputation: 744

You need to specify the key which you want to translate.

# 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

Upvotes: 1

Related Questions