-
Notifications
You must be signed in to change notification settings - Fork 506
Expand file tree
/
Copy pathanagram.py
More file actions
37 lines (32 loc) · 955 Bytes
/
anagram.py
File metadata and controls
37 lines (32 loc) · 955 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
26
27
28
29
30
31
32
33
34
35
36
37
"""
Author: OMKAR PATHAK
Created On: 17th August 2017
"""
from collections import Counter
import inspect
def is_anagram(word, _list):
"""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 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.
:param word: word
:param _list: list of words
:return: anagrams
"""
word = word.lower()
anagrams = []
for words in _list:
if word != words.lower():
if Counter(word) == Counter(words.lower()):
anagrams.append(words)
return anagrams
def get_code():
"""
returns the code for the is_anagram function
:return: source code
"""
return inspect.getsource(is_anagram)