Sponsored Reserved space — layout preview until AdSense is connected
medium +22 pts

Group anagrams

Sorted key for anagram buckets.

Implement `group_anagrams(words: list[str]) -> list[list[str]]`. Return a list of groups; within each group words are anagrams. Order of groups and words within groups doesn't matter for comparison.

Constraints

0 ≤ len(words) ≤ 10^4; words contain only lowercase letters.

Example

>>> group_anagrams(["eat","tea","tan","ate","nat","bat"])
[["eat","tea","ate"],["tan","nat"],["bat"]]
22 points ~20 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use tuple(sorted(word)) as the dict key.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected