title: Why does min() in Python return the key when a lambda is used on dictionaries?
body: <p>I am studying the Python Cookbook, 3rd edition. I encountered the code below:</p>
  
  <pre><code>prices = {'ACME': 45.23,'AAPL': 612.78,'IBM': 205.55,'HPQ': 37.20,'FB': 10.75}
  
  min(prices, key=lambda k: prices[k])
  </code></pre>
  
  <p>I tested this on Python 3.6.0, and it returns 'FB'.</p>
  
  <p>My understanding is that every key from the <code>prices</code> dictionary is sent to the lambda as parameter <code>k</code> and then the lambda returns the value associated with key <code>k</code> in the <code>prices</code> dictionary. So after iterating through all the keys, a list of values is returned which is used as an argument to the <code>min</code> function which finally returns the minimum value (in this case 10.75) in the dictionary.</p>
  
  <p>But when I ran the code, the program printed out the key (in this case 'FB'). Where am I wrong?</p>
  
  <p>I have gone through the documentation. It said <code>min</code> returns the smallest item in an iterable. I know <code>min</code> processes the keys and not the values. I just don't understand how it returns the key when the lambda returns a list of values. Help me please.</p>
  
  <p><strong>EDIT</strong>: Sorry for the edit. I am trying to find the key of the smallest value in the dictionary. The above code works perfectly but I don't know how it works.</p>