Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-091

Anagram Grouping

Problem

Group words by their anagram signature, the string of lowercased characters sorted alphabetically.

Return a dictionary mapping each signature to the alphabetically sorted list of its words.

Hint

Sorting the lowercase characters of an anagram is invariant.

Test cases

case 1
in: [["eat","tea","tan","ate","nat","bat"]]
expected: {"aet":["ate","eat","tea"],"ant":["nat","tan"],"abt":["bat"]}
case 2
in: [["a","a"]]
expected: {"a":["a","a"]}
case 3
in: [[]]
expected: {}
case 4
in: [["Listen","Silent"]]
expected: {"eilnst":["Listen","Silent"]}
Starter codePython
def anagram_grouping(words):
    # Your code here
    pass

4 test cases · run your code against them in the editor