Loading...
Loading...
Loading...
A word list holds words in lowercase. Put words that are anagrams of each other in one group.
Print one line per group. Inside a line, the words are sorted alphabetically and separated by spaces, and a word that repeats in the list appears each time. Order the lines by their first word.
Example
Input
stop pots tan opts nat bat
Output
bat nat tan opts pots stop
Three groups: bat, nat tan, opts pots stop.
Try the problem first. Open one hint at a time.
Two words are anagrams when their letters sorted give the same text. Use that text as the dictionary key.
Group the words with setdefault. Then sort each group, and sort the list of groups, which orders them by first word.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor