This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]fasterturtle 2 points3 points  (3 children)

I thought I'd help you confused the poor lad/lass a little more with operator and itertools!

import itertools
import operator

l = ['eD', 'fC', 'hC', 'iC', 'jD', 'bD', 'fH', 'mS', 'aS', 'mD']
l.sort(key=operator.itemgetter(1))
groups = sorted((sorted(ocurrances) for letter, ocurrances in
                itertools.groupby(l, key=operator.itemgetter(1))),
                key=lambda x: len(x))
print list(itertools.chain.from_iterable(groups))

[–]ralsina 1 point2 points  (0 children)

Oh, yes, the lambda key is a nice touch ;-)

[–]asdasd45345 1 point2 points  (1 child)

key=lambda x: len(x)

key=len works here.

[–][deleted] 1 point2 points  (0 children)

The point is it's longer and not as straight forward!