anagram exercise

This commit is contained in:
Xevion
2019-07-17 01:01:19 -05:00
parent 2221621fb8
commit 816237952a
4 changed files with 128 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
def find_anagrams(word, candidates):
word, lowercandidates = word.lower(), list(map(lambda item : item.lower(), candidates))
build = {char : word.count(char) for char in word.lower()}
return [candidates[index] for index, candidate in enumerate(lowercandidates) if {char : candidate.count(char) for char in candidate} == build and candidate != word]