By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Complete the code challenge below. Read the instructions carefully and use the integrated editor on the right to write and run your solution.
Anagrams are words that contain exactly the same letters ('eat', 'tea', 'ate'). Group all anagrams together from a list of words.
Key insight: two words are anagrams if and only if their sorted letters are identical. Use sorted(word) as a dictionary key to group them.
# Hint
sorted('eat') # ['a', 'e', 't']
sorted('tea') # ['a', 'e', 't']Use a defaultdict(list) to avoid checking if the key exists before appending.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.