title: Replacing a word in a list with a value from a dict
body: <p>I'm trying to create a simple program that lets you enter a sentence which will then be split into individual words, saved as <code>splitline</code>. For example:</p>
  
  <pre><code>the man lives in a house
  </code></pre>
  
  <p>Each word will be matched against a dict that contains a number of words stored against values such as:</p>
  
  <pre class="lang-python prettyprint-override"><code>mydict = {"the":1,"in":2,"a":3}
  </code></pre>
  
  <p>If the word is present in the dict, then I want the word to be replaced with the key associated with the value so that the output will look like:</p>
  
  <pre><code>1 man lives 2 3 house
  </code></pre>
  
  <p>I created some code that allows me to test if each word exists in the dict which was then able to output 'true' or 'false' for every word in the sentence but when I tried to replace the word with the key from the dict I goit a little stuck.</p>
  
  <p>Here's what I tried so far:</p>
  
  <pre class="lang-python prettyprint-override"><code>text = input("Enter a sentence \n")
      for word in text:
          splitline = text.split(" ")
  
  mydict = {"the":1,"in":2,"a":3}
  
  for word in splitline:
      if word in dict.keys(mydict):
  
          #I tried to declare x as the value from the dict
          x = str(dict.values(mydict))
  
          #newline should be the original splitline with word replaced with x
          newline = splitline.replace(word,x)
  
          #the program should print the newline with word replaced with key
          print(newline)
  </code></pre>
  
  <p>It seems I can't use <code>splitline.replace</code> with <code>dict.keys(mydict)</code> as I assume that it will select all of the keys and not just the instance I am trying to deal with. Is there a way I can do this?</p>
  
  <p>I hope I've explained myself properly.</p>