Hi I wanted to ask if this what you see below is quickest and most efficient way to translate words in python. I only need translation to english from other foreign languages. Would it be more efficient to divide dictionary into one dictionary for every language or is it good the way it is right now? It would be nice if code would work in python 2.7 and 3.x and above. In code below I have to change iteritems to items which is no big deal.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
dct = {'apple': ['apfel', 'pomme', 'manzana', 'jabłko'],
'pineapple': ['ananas', 'ananas', 'piña', 'ananas']}
def translate(q):
for eng_word, trans_list in dct.iteritems():
for trans_word in trans_list:
if trans_word == q:
q = eng_word
print q
return q
query = 'pomme'
query = translate(query)
query = 'ananas'
query = translate(query)
print query