title: Python list group by
body: <p>I have a python list like this:</p>
  
  <pre><code>Category    Title   ProductId   Rating
  'Electronics, Books, Bundles'   Lautner e-Reader Cover  161553  4
  'Electronics, Books, Bundles'   Lautner stand in e-Reader Cover 161552  3
  'Electronics, Books, Bundles'   Lautner Chocolate NOOK Case 594451  5
  'Electronics, Books, Bundles'   Oliver e-Reader Cover   161685  1
  'Electronics, Books, Covers'    Dessin Leather Cover for Nook Color; Nook Tablet Digital Reader 594033  4.3
  'Electronics, Books, Covers'    Emerson Quote e-Reader Cover    161542  2.8
  'Electronics, Books, Covers'    Industriell Easel e-Reader Cover    161682  3.7
  'Electronics, Books, Covers'    Jonathan Adler Book Reader Cover Hd - Elephant  594548  4.9
  'Electronics, Scanners, Covers' Lyra Light Front Cover for NOOK eR  161683  4
  'Electronics, Scanners, Covers' Nook Tablet Dessin Cover in Marine  161686  3.8
  'Electronics, Scanners, Covers' Nook Tablet Horizontal Stand Cover in Red   594202  4.2
  'Electronics, Scanners, Covers' Canvas Bella Library Cover  161554  3
  'Electronics, Books, Radios'    Groovy Protective Stand Cover: Custom Designed for 7-inch NOOK HD   594549  3.8
  'Electronics, Books, Radios'    Hd Groovy Stand In Blue- Nook   594514  4.1
  'Electronics, Books, Radios'    Hutton Envelope in Bark 161560  2.9
  'Electronics, Books, Radios'    Italian Leather-Style Chesterton Cover for NOOK Reader  161561  4
  </code></pre>
  
  <p>Out of all these list values, I want top k from each category. Top 2 should give the below result:</p>
  
  <pre><code>'Electronics, Books, Bundles'   Lautner Chocolate NOOK Case 594451  5
  'Electronics, Books, Bundles'   Lautner e-Reader Cover  161553  4
  'Electronics, Books, Covers'    Jonathan Adler Book Reader Cover Hd - Elephant  594548  4.9
  'Electronics, Books, Covers'    Dessin Leather Cover for Nook Color; Nook Tablet Digital Reader 594033  4.3
  'Electronics, Books, Radios'    Hd Groovy Stand In Blue- Nook   594514  4.1
  'Electronics, Books, Radios'    Italian Leather-Style Chesterton Cover for NOOK Reader  161561  4
  'Electronics, Scanners, Covers' Nook Tablet Horizontal Stand Cover in Red   594202  4.2
  'Electronics, Scanners, Covers' Lyra Light Front Cover for NOOK eR  161683  4
  </code></pre>
  
  <p>Adding whatever I have tried:</p>
  
  <pre><code>sorted_data = sorted(data, key=operator.itemgetter(1), reverse=True)
  
  k = int(sys.argv[1])
  for result in sorted_data[:k]:
      print result
  </code></pre>
  
  <p>Here I am passing 'k' as a command line argument to the python file.</p>