Anagram pairs
Read a line of lower-case words. Group the words that are anagrams of each other (same letters, different order).
Print each group on its own line with its words in alphabetical order, separated by spaces. Order the groups by their first word, alphabetically. Words with no anagram partner form a group of one.
Input
listen silent enlist google
Expected output
enlist listen silent google
Input
abc bca cab xyz
Expected output
abc bca cab xyz
Show a hint
Two words are anagrams when their sorted letters are equal, so sorted letters make a perfect dictionary key.
Show a solution
Loading the editor…
Run the tests to check your solution.