We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
python3 detailed program without shortcuts to understand better
!/bin/python3
import sys
from itertools import repeat
def makingAnagrams(s1, s2):
l1=list(s1)
l2=list(s2)
l11=list(repeat(0,26))
l22=list(repeat(0,26))
count=0
for i in l1:
l11[97-ord(i)]+=1
for i in l2:
l22[97-ord(i)]+=1
for i in range(26):
count=count+abs(l11[i]-l22[i])
return(count)
Making Anagrams
You are viewing a single comment's thread. Return to all comments →
python3 detailed program without shortcuts to understand better
!/bin/python3
import sys from itertools import repeat
def makingAnagrams(s1, s2): l1=list(s1) l2=list(s2) l11=list(repeat(0,26)) l22=list(repeat(0,26)) count=0 for i in l1: l11[97-ord(i)]+=1 for i in l2: l22[97-ord(i)]+=1 for i in range(26): count=count+abs(l11[i]-l22[i]) return(count)
s1 = input().strip() s2 = input().strip() result = makingAnagrams(s1, s2) print(result)