20 August 2026
Anagram Groups
Medium
Dictionaries
Sort scrambled words back into their anagram families.
Given a list of lowercase words, group every word with the others that are its anagrams (same letters, any order). Return the groups as a list of lists, each group listing its words in the order they first appeared, and the groups themselves ordered by each group's first appearance.
Constraints
0 <= len(words) <= 300Each word contains only lowercase English letters1 <= len(word) <= 50 for every word
Function signature
def anagram_groups(words):