Challenge Description: An anagram is a word or phrase formed by rearranging the letters of another word or phrase. For example, "listen" and "silent" are anagrams. In this challenge, your task is to write a program or function that takes a list of strings as input and returns the unique anagrams.
Write a program or function that takes a list of strings as input and returns the unique anagrams, preserving the order of appearance. Your solution should handle lowercase letters (a-z) only.
Examples:
Input | Output |
---|---|
["cat", "act", "tac", "dog", "god"] |
["cat", "dog"] |
["a", "ab", "abc", "abcd"] |
["a", "ab", "abc", "abcd"] |
["cat", "dog", "tac", "god", "act"] |
["cat", "dog"] |
The input list contains five strings. The strings "cat", "act", and "tac" are anagrams of each other, and "dog" and "god" are anagrams of each other. The output should contain only one representative from each group of anagrams, preserving the order of appearance. Hence, the output is ["cat", "dog"]
.
Requirements:
The input list can contain duplicate strings, and they should be considered as separate entities. The output should contain only one representative from each group of anagrams, preserving the order of appearance. The input list may contain an arbitrary number of strings. The input list and the output list can be empty.
This is code-golf, so the shortest solution in bytes is the winner.
Good luck!