input: [\'abc\', \'cab\', \'cafe\', \'face\', \'goo\']
output: [[\'abc\', \'cab\'], [\'cafe\', \'face\'], [\'goo\']]
The problem is simple: it grou
Just to simplify the previous working answer a little, so that it's more 'readable' (extracting the sorted(words....) step out:
>>> words = ['abc', 'eat', 'face', 'cab', 'tea', 'goo']
>>> words = sorted(words, key=sorted)
>>> words
['abc', 'cab', 'face', 'eat', 'tea', 'goo']
>>> [list(group) for key,group in groupby(words, sorted)]
[['abc', 'cab'], ['face'], ['eat', 'tea'], ['goo']]
As groupby expected the Sequence is in sorted order.