title: Replace dictionary keys with values
body: <p>I have made a dictionary from a text file and want to use it to replace the keys that appear in a separate file with their values.  </p>
  
  <p>For example, my dictionary looks something like...  </p>
  
  <pre><code>names = {1:"Bob", 2:"John", 3:"Tom"}
  </code></pre>
  
  <p>And the other file looks something like...  </p>
  
  <pre><code>1 black cat  
  2 gray elephant  
  3 brown dog  
  </code></pre>
  
  <p>I want it to end up being...  </p>
  
  <pre><code>Bob black cat  
  John gray elephant  
  Tom brown dog  
  </code></pre>
  
  <p>So far I have only written code to make the dictionary  </p>
  
  <pre><code>names = {}  
  for line in open("text.txt", 'r'):  
      item = line.split()  
      key, value = item[0], item[2]  
      names[key] = value  
  </code></pre>
  
  <p>I want to open a second file and use the names dictionary to replace the keys that appear there with their values. I have seen that you can use <code>replace(key, dict[key])</code> but am not sure how.</p>