
At Notion, you are asked to organize a list of words into groups where each group contains words that are anagrams of one another. Write code that is modular, readable, and easy to test.
Implement a function that takes a list of lowercase strings and returns a list of groups, where each group contains all words that are anagrams. Two words are anagrams if they contain the same characters with the same frequencies.
words, a list of stringsExample 1
words = ["eat", "tea", "tan", "ate", "nat", "bat"][["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]Example 2
words = [""][[""]]1 <= len(words) <= 10^40 <= len(words[i]) <= 100words[i] contains only lowercase English letterswords = ["eat", "tea", "tan", "ate", "nat", "bat"]Output[["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]WhyThe words "eat", "tea", and "ate" share the same sorted signature, as do "tan" and "nat".words = [""]Output[[""]]WhyAn empty string is grouped with itself.words = ["a"]Output[["a"]]WhyA single word forms one group.1 <= len(words) <= 10^40 <= len(words[i]) <= 100words[i] contains only lowercase English lettersOutput group order does not matterOrder of words within each group does not matterdef group_anagrams(words):