I want to check if two strings are anagrams. For example, if my word is "halo", I want to check if those letters appear in "loha". It should match because it's an anagram.
My attempt fails and I'm not sure why. My code and output is below. I have a list of words and I want to check to see which elements are anagrams in the list.
def anagram(myList):
for elem in myList:
chars = set(elem)
if all((c in chars) for c in myList):
print "Yes, anagram ", elem, chars
else:
print "NOT anagram ", elem, chars
wordsList = ["halo", "loha", "ahlo", "sully"]
anagram(wordsList)
And here's my output
NOT anagram halo set(['a', 'h', 'l', 'o'])
NOT anagram loha set(['a', 'h', 'l', 'o'])
NOT anagram ahlo set(['a', 'h', 'l', 'o'])
NOT anagram sully set(['y', 's', 'u', 'l'])