Andreas Kostyrka wrote: > l.sort(key=lambda x: (x.content_type, x.submit_date)) > > Now, you can construct a sorted list "t": > > t = [] > for key, item_iterator in itertools.groupby(l, key=lambda x: (x.content_type, > x.submit_date)): > sorted_part = sorted(item_iterator, key=lambda x: x.submit_date) > t.append((sorted_part[-1].submit_date, key, sorted_part))
I think you mean for key, item_iterator in itertools.groupby(l, key=lambda x: (x.content_type)): # Group by content type only sorted_part = list(item_iterator) # No need to sort again t.append((sorted_part[-1].submit_date, key, sorted_part)) Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor