title: Reduce by key in python
body: <p>I'm trying to think through the most efficient way to do this in python.</p>
  
  <p>Suppose I have a list of tuples:</p>
  
  <pre><code>[('dog',12,2), ('cat',15,1), ('dog',11,1), ('cat',15,2), ('dog',10,3), ('cat',16,3)]
  </code></pre>
  
  <p>And suppose I have a function which takes two of these tuples and combines them:</p>
  
  <pre><code>def my_reduce(obj1, obj2):
      return (obj1[0],max(obj1[1],obj2[1]),min(obj1[2],obj2[2]))
  </code></pre>
  
  <p>How do I perform an efficient reduce by 'key' where the key here could be the first value, so the final result would be something like:</p>
  
  <pre><code>[('dog',12,1), ('cat',16,1)]
  </code></pre>