Skip to content

Commit 1dd3f7f

Browse files
committed
Added anagram implementation
1 parent b43b647 commit 1dd3f7f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pygorithm/string/anagram.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Author: OMKAR PATHAK
2+
# Created On: 17th August 2017
3+
4+
from collections import Counter
5+
6+
def is_anagram(word, List):
7+
'''
8+
ANAGRAM: An anagram is direct word switch or word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once
9+
We are taking a word and a list. We return the anagrams of that word from the given list and return the list of anagrams else return empty list
10+
'''
11+
word = word.lower()
12+
anagrams = []
13+
for words in List:
14+
if word != words.lower():
15+
if Counter(word) == Counter(words.lower()):
16+
anagrams.append(words)
17+
return anagrams
18+
19+
def get_code():
20+
""" returns the code for the current class """
21+
import inspect
22+
return inspect.getsource(is_anagram)

0 commit comments

Comments
 (0)