-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValid_Anagram.py
More file actions
44 lines (32 loc) · 872 Bytes
/
Copy pathValid_Anagram.py
File metadata and controls
44 lines (32 loc) · 872 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
38
39
40
41
42
43
44
# time efficient
def isAnagram(s, t):
sums = 0
if len(s) != len(t):
return False
else:
set_s = set(s)
for i in set_s:
if s.count(i) != t.count(i):
return False
return True
s = input("Enter first string: ")
t - input("Enter second string: ")
output = isAnagram(s, t)
print(output)
# slower
def isAnagram(s, t):
sums = 0
if len(s) != len(t):
return False
else:
for i in s:
if s.count(i) == t.count(i):
sums += 1
if sums == len(s):
return True
else:
return False
s = input("Enter first string: ")
t - input("Enter second string: ")
output = isAnagram(s, t)
print(output)