0

I am having trouble with Tuccin to English. I can get it to translate in from English to Tuccin only. What I want is if word is English translate to Tuccin, If word is Tuccin, translate to English full phrases. And finally if any input words are not stored I want it To print that same word in its own place so show there was Nothing to translate it to.

#Translator.py
Tuc={"i":["o"],"love":["wau"],"you":["uo"],"me":["ye"],"my":["yem"],
     "mine":["yeme"],"are":["sia"]}
phrase=True
reverseLookup = False

while True:
    reverseLookup = False
    translation = str(raw_input("Enter content for translation.\n").lower())
    input_list = translation.split()

#English to Tuccin
if phrase ==True:
    print "*English Detected!"

    for word in input_list:
        if word in Tuc:
            print ("".join(Tuc[word]))
        else:
            reverseLookup = True

#Tuccin to english
elif phrase == True and reverseLookup == True:
    print "*Tuccin Detected!"
    input_list = translation.split()
    for k, v in Tuc.iteritems():
        if translation in v:
            print k

        else:
            print "Word Not Stored!"
            reverseLookup = False
            print word
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

-1

This stack answer demonstrates how to quickly invert a simple dictionary. So, in your case, what you would do is:

Eng = {t[0]: [e] for t, e in Tuc.items()}

and use this dictionary the same way you've used the Tuc dictionary.

It would be easier if your Tuc dictionary didn't have redundant lists as values:

Tuc = {'me': 'ye', 'love': 'wau', 'i': 'o', 'mine': 'yeme', 'are': 'sia', 'you': 'uo', 'my': 'yem'}
Eng = {t: e for t, e in Tuc.items()}
Community
  • 1
  • 1
apteryx
  • 1,105
  • 7
  • 14