Finding and grouping anagrams by Python
问题 input: ['abc', 'cab', 'cafe', 'face', 'goo'] output: [['abc', 'cab'], ['cafe', 'face'], ['goo']] The problem is simple: it groups by anagrams . The order doesn't matter. Of course, I can do this by C++ (that's my mother tongue). But, I'm wondering this can be done in a single line by Python . EDITED: If it's not possible, maybe 2 or 3 lines. I'm a newbie in Python. To check whether two strings are anagram, I used sorting. >>> input = ['abc', 'cab', 'cafe', 'face', 'goo'] >>> input2 = [''.join