title: How to find a key using a value in a python 3 dictionary?
body: <p>I am writing a cypher and I've assigned numerical values to every letter in the alphabet, <code>alphabet_dictionary = {'a': 0, 'b': 1, 'c': 2,... etc.}</code>.</p>
  
  <p>I first convert the letter in <code>message</code> to numbers, do some arithmetic and store those numbers in a variable named <code>code</code>.</p>
  
  <p>I want to convert them back to letters.</p>
  
  <p>So far I have:</p>
  
  <pre><code>for number in code:
      for letter, value in alphabet_dictionary.items():
          if value == number:
              coded_message.append(letter)
  </code></pre>
  
  <p>This works. I end up with a the correct coded message inside my <code>coded_message</code> list. Is there is something better or more efficient?</p>
  
  <p>Why can't I do that in a single line? I first tried using:</p>
  
  <pre><code>for number in code:
      coded_message.append(letter for letter, value in alphabet_dictionary.items() if value == number)
  </code></pre>
  
  <p>but that only appends the memory allocation address for the individual characters for example: </p>
  
  <pre><code>`[&lt;generator object &lt;genexpr&gt; at 0x1011bb240&gt;, &lt;generator object &lt;genexpr&gt; at 0x1011bb1f8&gt;, &lt;generator object &lt;genexpr&gt; at 0x1011bb288&gt;, &lt;generator object &lt;genexpr&gt; at 0x1011bb2d0&gt;, &lt;generator object &lt;genexpr&gt; at 0x1011bb318&gt;, &lt;generator object &lt;genexpr&gt; at 0x1011bb360&gt;, &lt;generator object &lt;genexpr&gt; at 0x1011bb3a8&gt;]'
  </code></pre>
  
  <p>Why is this happening?</p>