Skip to content

Commit

Permalink
Update is_anagram.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh Singhal authored Jun 4, 2019
1 parent 1293dfd commit 97eef9e
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions is_anagram.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Check if two strings are anagrams of each other

def is_anagram(str1, str2):
def anagramise(word):
d = dict()

for char in word:
if char not in d.keys():
d[char] = 1
else:
d[char] += 1

return d

if len(str1) == len(str2):
for i in str1:
if i in str2:
pass
else:
return False
return True
else:
return False
def is_anagram(str1, str2):
return anagramise(str1) == anagramise(str2)

result = is_anagram("hello", "billion")
print(result) # False

0 comments on commit 97eef9e

Please sign in to comment.