-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagram.py
More file actions
36 lines (27 loc) · 712 Bytes
/
Anagram.py
File metadata and controls
36 lines (27 loc) · 712 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
def anagram(s1,s2):
s1=s1.replace(' ','').lower()
s2 = s2.replace(' ', '').lower()
return sorted(s1)==sorted(s2)
print(anagram('clint eastwood','old west action'))
# anagram 2
def anagram2(s1,s2):
s1=s1.replace(' ','').lower()
s2=s2.replace(' ','').lower()
# Edge case check
if len(s1) != len(s2):
return False
count = {}
for letter in s1:
if letter in count:
count[letter] += 1
else:
count[letter] = 1
for letter in s2:
if letter in count:
count[letter] -= 1
else:
count[letter] = 1
for k in count:
if count[k] != 0:
return False
return True