
At Meta, you are given a list of message tokens and need to group together words that are anagrams of each other. Two strings are anagrams if they contain the same characters with the same frequencies, possibly in a different order.
Write a function that takes a list of strings and returns a list of groups, where each group contains strings that are mutual anagrams. The order of groups does not matter, and the order of strings within each group does not matter.
strs, a list of lowercase English stringsExample 1
strs = ["eat", "tea", "tan", "ate", "nat", "bat"][["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]"eat", "tea", and "ate" share the same sorted form, so they belong in one group.Example 2
strs = [""][[""]]1 <= len(strs) <= 10^40 <= len(strs[i]) <= 100strs[i] contains only lowercase English lettersstrs = ["eat", "tea", "tan", "ate", "nat", "bat"]Output[["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]WhyWords with the same sorted character sequence are grouped together.strs = [""]Output[[""]]WhyThe empty string has an empty signature and forms its own group.strs = ["a"]Output[["a"]]WhyA single string is always one anagram group by itself.1 <= len(strs) <= 10^40 <= len(strs[i]) <= 100strs[i] contains only lowercase English lettersdef group_anagrams(strs):