-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAnagram.py
More file actions
25 lines (25 loc) · 806 Bytes
/
Anagram.py
File metadata and controls
25 lines (25 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def find_anagrams(word, candidates):
result = []
word = word.lower()
for candidate in candidates:
if candidate.lower() == word.lower():
continue
if len(candidate) != len(word):
continue
is_anagram = True
candidate2 = candidate.lower()
word2 = word
for char in candidate2:
if char not in word2:
is_anagram = False
break
for i in range(len(word2)):
if char == word2[i]:
if i == len(word2) - 1:
word2 = word2[:i]
break
word2 = word2[:i] + word2[i + 1:]
break
if is_anagram == True:
result.append(candidate)
return result