I am trying to print out the anagrams in a given list. I am unable to arrive at the right answer. I'd like to know where I am going wrong, and how can I fix it.
words = ['bat', 'rats', 'god', 'dog', 'cat', 'arts', 'star']
sort_words = []
anagrams = []
for word in words:
word.split()
word = ' '.join(sorted(word))
sort_words.append(word)
for i in range(len(sort_words)):
for j in range(len(sort_words)):
if sort_words[i] == sort_words[j]:
anagrams.append(sort_words[i])
print anagrams