title: Finding the largest/smallest object in a python generator/list
body: <p>Let's say I have a generator <code>gen</code> which yields some lists.  I'd like to find the longest list.</p>
  
  <p>I can do </p>
  
  <pre><code>max((len(L) for L in gen))
  </code></pre>
  
  <p>which will get me the length of the longest list, but at this point the list is gone to the mists of time.</p>
  
  <p>Alternately I could do</p>
  
  <pre><code>maxlength = 0
  for L in gen:
      if len(L)&gt;maxlength:
          savelist = L
          maxlength = len(L)
  </code></pre>
  
  <p>But it seems there should be a more pythonic way that avoids the for loop and the if statement.</p>
  
  <p><strong>edit</strong> just a comment to help others who might search for related problems:
  Finding the smallest object with <code>min</code> can be done equivalently, and the same approach will work if <code>gen</code> is a list instead.</p>