-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathcheckStrings.py
More file actions
47 lines (41 loc) · 1.02 KB
/
checkStrings.py
File metadata and controls
47 lines (41 loc) · 1.02 KB
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
45
46
47
# A program to check whether the string contains equal & same no of characters
import collections
def check_strings(word1, word2):
word1 = list(word1)
word2 = list(word2)
dict1 = {}
dict2 = {}
flag = True
for i in word1:
if i in dict1:
dict1[i] = dict1[i] + 1
continue
else:
dict1[i] = 1
for i in word2:
if i in dict2:
dict2[i] = dict2[i] + 1
continue
else:
dict2[i] = 1
if len(dict1) == len(dict2):
for k, v in dict1.items():
if k in dict2:
if dict2[k] == v:
continue
else:
flag = False
break
else:
flag = False
break
if flag:
print("Same")
else:
print("Not Same")
def main():
word1 = input("Enter first string : ")
word2 = input("Enter second string : ")
check_strings(word1, word2)
word = "madam"
main()