You are viewing a single comment's thread. Return to all comments →
I like your solution and altered it a bit using set operations so that it only considers the elements in a,b.
If other characters are introduced there will be no need to update the code and the loop only covers the elements present in both strings:
def makeAnagram(a, b): offset = 0 aset = set(a) bset = set(b) allset = set(aset | bset) for i in allset: ia = a.count(i) ib = b.count(i) offset += abs(ia-ib) return offset
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
I like your solution and altered it a bit using set operations so that it only considers the elements in a,b.
If other characters are introduced there will be no need to update the code and the loop only covers the elements present in both strings: