Given a string, we must split it into two contiguous substrings, then determine the minimum number of characters to change to make the two substrings into anagrams of one another.
def anagram(s):
flag = 0
if len(s)%2 != 0: return -1
else:
temp1,temp2 = s[:len(s)//2],s[len(s)//2:]
temp1 = ''.join(sorted(temp1))
temp2 = ''.join(sorted(temp2))
for i in temp1:
flag1 = temp2.count(i)
if flag1>1: flag1 = 1
else: flag1 = flag1
flag += flag1
return flag
I'm sort of all over the place and highly complicating this without getting it right. Is there any way to simplify the logic?