Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 97eef9e

Browse files
author
Amogh Singhal
authored
Update is_anagram.py
1 parent 1293dfd commit 97eef9e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

‎is_anagram.py‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# Check if two strings are anagrams of each other
22

3-
def is_anagram(str1, str2):
3+
def anagramise(word):
4+
d = dict()
5+
6+
for char in word:
7+
if char not in d.keys():
8+
d[char] = 1
9+
else:
10+
d[char] += 1
11+
12+
return d
413

5-
if len(str1) == len(str2):
6-
for i in str1:
7-
if i in str2:
8-
pass
9-
else:
10-
return False
11-
return True
12-
else:
13-
return False
14+
def is_anagram(str1, str2):
15+
return anagramise(str1) == anagramise(str2)
1416

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /