title: How to get the min/max in a list by using a lambda or function to get a comparison value from the item?
body: <p>In Python I want to find the max element in a list using a lambda for comparison.</p>
  
  <p>No success with this code:</p>
  
  <pre><code># An 'anonymous' object, like JSON object. Use like: Mock(name='Bob', age=30)
  class Mock(object):
      def __init__(self, **kwargs):
          self.__dict__.update(kwargs)
  
  items = [
      Mock(cost=10, quantity=1),
      Mock(cost=15, quantity=3),
      Mock(cost=20, quantity=5),
      Mock(cost=100, quantity=2)
  ]
  
  index, value = max(items, key=lambda(item) : item.cost * item.quantity)
  print('$%d, q=%d' % (value.cost, value.quantity))
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>    index, value = max(items, key=lambda(item) : item.cost * item.quantity)
  TypeError: 'Mock' object is not iterable
  </code></pre>
  
  <p>How can I implement this correctly?</p>