Frequency of single character can be possibly changed , so change its parity
for j in range ( 26 ) : NEW_LINE INDENT changedCount = a [ : ] NEW_LINE if ( a [ j ] == 0 ) : NEW_LINE INDENT changedCount [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT changedCount [ j ] = 0 NEW_LINE DEDENT ans += mp [ tuple ( changedCount ) ] NEW_LINE DEDENT mp [ tuple ( a ) ] += 1 NEW_LINE return ans NEW_LINE