Function : User enters a word in korean and the program translates (defines) it in english.
What improvements can I make?
Extra : What other challenges would you recommend that incorporates both JSON and python?
KoreanDictionary.py
import json
from difflib import get_close_matches
korean_data = json.load(open("korean_vocabulary.json"))
def my_translator(word):
if word in korean_data.keys():
return korean_data[word]
elif len(get_close_matches(word,korean_data.keys(),n=1,cutoff=.69)) > 0:
word = get_close_matches(word,korean_data.keys(),n=1,cutoff=.69)[0]
return korean_data[word]
else:
return "Word does not exist."
if __name__ == '__main__':
user_input = input("Define:")
definition = str(my_translator(user_input)).replace('[','').replace(']','').replace("'",'')
print(user_input + ": " + definition)
korean_vocabulary.json
{"안녕하세요": ["hello"],"죽어버려": ["GO DIE"],"상황": ["situation"],"어려워": ["hard; difficult"],
"모르겠다": ["I don't know."],"조건": ["condition"],"정규직 직업": ["full-time job"],
"탈락": ["eliminate; out"], "눈치": ["quick to catch; tactfulness"],"슬픈": ["sad"],
"복잡한": ["complicated"],"완전": ["completely"],"반대": ["opposite"],"대박": ["jackpot; awesome"],
"어꺠": ["shoulders"],"얼굴": ["face"]}