> For the complete documentation index, see [llms.txt](https://chiragjain.gitbook.io/neetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chiragjain.gitbook.io/neetcode/49-group-anagrams/code.md).

# CODE

```python
class Solution:
    def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
        result = {}
        for s in strs:
            key = [0 for _ in range(26)]
            for c in s: 
                key[ord(c) - ord('a')] += 1
            key = tuple(key)
            if key not in result:
                result[key] = []
            result[key].append(s)
        return list(result.values())
        
```
