News for hackers. Stuff that matters.
Re:Ruby is beautiful (but I'm moving to Python) by irahul on Monday November 29, 2010 @06:44AM (#1950007)
The groupby, if done using itertools, will cut some code.

  from itertools import groupby

  customer_data = (line.strip().split(',') for line in     file('customer.txt'))
  grouped_ages = groupby(customer_data, key=itemgetter(1))
  print sorted((len(list(g)), k) for k, g in grouped_ages)[-3:]
Re:Ruby is beautiful (but I'm moving to Python) by anthonyb on Monday November 29, 2010 @05:46PM (#1952136)
Ah yes, I'd forgotten about groupby. You'll also need to do a

   from operator import itemgetter
as well.