[Python] Creating a dictionary in Python and using it to translate a word

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    I have created a Spanish-English dictionary in Python and I have stored it using the variable translation. I want to use that variable in order to translate a text from Spanish into English. This is the code I have used so far:

    from corpus.nltk import swadesh
    import my_books

    es2en = swadesh.entries(['es', 'en'])
    translation = dict(es2en)

    for sentence in my_books.sents("book_1"):
    for word in my_books.words("book_1"):
    if word in es2en:
    print(translation, end= " ")
    else:
    print("unknown_word", end= " ")
    print("")


    My problem is that none of the words in book_1 is actually translated into English, so I get a text full of unknown word. I think I'm probably using translation in the wrong way... how could I achieve my desired result?

    Continue reading...

Compartilhe esta Página