forked from srishilesh/Data-Structure-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaking_Anagrams.py
48 lines (39 loc) · 902 Bytes
/
Making_Anagrams.py
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
48
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the makingAnagrams function below.
def makingAnagrams(s1, s2):
map1 = {}
map2 = {}
tot = list(set(s1+s2))
for i in s1:
if i not in map1:
map1[i] = 1
else:
map1[i]+=1
for i in s2:
if i not in map2:
map2[i] = 1
else:
map2[i]+=1
count = 0
#result = []
for i in map1:
if i in map2:
#print(map1[i],map2[i])
count+=min(map1[i],map2[i])
for i in map2:
if i in map1:
print(i)
count+=min(map1[i],map2[i])
return len(s1)+len(s2)-count
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s1 = input()
s2 = input()
result = makingAnagrams(s1, s2)
fptr.write(str(result) + '\n')
fptr.close()