I want to write a function that finds anagrams. Anagrams are words that are written with the same characters. For example, "abba" and "baba".
I have gotten as far as writing a function that can recognize if a certain string has the same letters as another string. However, I can't account for the number of repeated letters in the string.
How should I do this?
This is the code I have written so far:
def anagrams(word, words):
list1 = []
for i in words:
if set(word) == set(i):
list1.append(i)
return list1
The inputs look something like this:
('abba', ['aabb', 'abcd', 'bbaa', 'dada'])
I want to find an anagram for the first string, within the list.