Write a function that will find all the anagrams of a word from a list. You will be given two inputs a word and an array with words.
Hi can some kind soul explain to me how this 2 function is different? One only returns the first value the for loops found.... why is that so?
def anagrams(word, words):
for item in words:
if sorted(item) == sorted(word):
return [item]
def anagram(word, words):
return [item for item in words if sorted(item) == sorted(word)]
print(anagrams('racer', ['crazer', 'carer', 'racar', 'caers', 'racer']))
print(anagram('racer', ['crazer', 'carer', 'racar', 'caers', 'racer']))
['carer']
['carer', 'racer']