input: [\'abc\', \'cab\', \'cafe\', \'face\', \'goo\'] output: [[\'abc\', \'cab\'], [\'cafe\', \'face\'], [\'goo\']]
The problem is simple: it grou
the unreadable, one-line solution:
>>> import itertools >>> input = ['abc', 'face', 'goo', 'cab', 'cafe'] >>> [list(group) for key,group in itertools.groupby(sorted(input, key=sorted), sorted)] [['abc', 'cab'], ['cafe', 'face'], ['goo']]
(well, it is really 2 lines if you count the import...)