I have a starting file which has values on each line separated by a comma, like so:
hello,welcome
hi, howareyou
hola,comoestas
I want to take those words and put them into a dictionary so they are key/value pairs. Then i am trying to ask for a key and return the corresponding value. I believe i am close so any help would be appreciated. Also i am a beginner so simple code is best.
def CreateDictionary():
WordDictionary = open('file.csv', 'r')
for line in WordDictionary:
mylist = line.split(',')
return(mylist)
def main():
cd = CreateDictionary()
text=input('input text:')
for x in cd.values():
if x == text:
word=cd[x]
print(word)
main()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…