title: How can I translate from one file to another using a dictionary?
body: <p>I have a variable dictionary in this form:
  <code>dictionary = {'hello':hola', 'good night':'buenos nochas'}</code></p>
  
  <p>My question is, how can I use this dictionary to translate from one file to another one, where my input is a file in English?</p>
  
  <p>I know about using keys and values, but my output isn't what I was thinking it would be.  My code translates some words in the middle of them if this word is in build_dictionary.</p>
  
  <p>Code:</p>
  
  <pre><code>dictionary_words = open("dict.txt" , "r").readlines()
  
  x = []
  t = []
  for line in dictionary_words:
      words= line.split()
      x.append(besede[0])
      t.append(besede[1])
  build_dictionary = dict(zip(x,t))
  
  text = open('text.txt', mode = 'r').read()
  
  for key in build_dictionary.keys():
      text = build_dictionary.replace(key,slovar[key])
  
  output = open('translation.txt', mode = 'w')
  output.write(text)
  output.close
  </code></pre>