Your task is to Combine two Strings. But consider the rule...

By the way you don't have to check errors or incorrect input values, everything is ok without bad tricks, only two input strings and as result one output string;-)...

And here's the rule:  
Input Strings `a` and `b`: For every character in string `a` swap the casing of every occurrence of the same character in string `b`. Then do the same casing swap with the inputs reversed. Return a single string consisting of the changed version of `a` followed by the changed version of `b`. A char of `a` is in `b` regardless if it's in upper or lower case - see the testcases too.  
I think that's all;-)...

Some easy examples:

````
Input: "abc" and "cde"      => Output: "abCCde" 
Input: "ab" and "aba"       => Output: "aBABA"
Input: "abab" and "bababa"  => Output: "ABABbababa"
````

Once again for the last example - description from `KenKamau`, see discourse;-):

a) swap the case of characters in string `b` for every occurrence of that character in string `a`  
char `'a'` occurs twice in string `a`, so we swap all `'a'` in string `b` twice. This means we start with `"bababa"` then `"bAbAbA"` => `"bababa"`  
char `'b'` occurs twice in string `a` and so string `b` moves as follows: start with `"bababa"` then `"BaBaBa"` => `"bababa"`

b) then, swap the case of characters in string `a` for every occurrence in string `b`  
char `'a'` occurs `3` times in string `b`. So string `a` swaps cases as follows: start with `"abab"` then => `"AbAb"` => `"abab"` => `"AbAb"`  
char `'b'` occurs `3` times in string `b`. So string `a` swaps as follow: start with `"AbAb"` then => `"ABAB"` => `"AbAb"` => `"ABAB"`.

c) merge new strings `a` and `b`  
return `"ABABbababa"`

There are some static tests at the beginning and many random tests if you submit your solution.

Hope you have fun:-)!

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def work_on_strings(a,b):
	

Solutions:
def work_on_strings(a, b):
	new_a = [letter if b.lower().count(letter.lower()) % 2 == 0 else letter.swapcase() for letter in a]
	new_b = [letter if a.lower().count(letter.lower()) % 2 == 0 else letter.swapcase() for letter in b]
	return ''.join(new_a) + ''.join(new_b)


from collections import Counter

def swap_them(a, b):
	cnt = Counter(b.lower())
	return ''.join((c.swapcase() if cnt[c.lower()] % 2 else c for c in a))

def work_on_strings(a, b):
	return swap_them(a, b) + swap_them(b, a)


def work_on_strings(a, b):
	A = list(a)
	B = list(b)
	for i in range(len(A)):
		for j in range(len(B)):
			if A[i].upper() == B[j] or A[i].lower() == B[j]:
				B[j] = B[j].swapcase()
	for i in range(len(B)):
		for j in range(len(A)):
			if B[i].upper() == A[j] or B[i].lower() == A[j]:
				A[j] = A[j].swapcase()
	return ''.join((str(i) for i in A + B))


from collections import Counter
import re

def swaper(m):
	return m[0].swapcase()

def buildPattern(s):
	return f"[{''.join((c for (c, n) in Counter(s.lower()).items() if n & 1)) or ' '}]"

def player(a, b):
	return re.sub(buildPattern(b), swaper, a, flags=re.I)

def work_on_strings(a, b):
	return player(a, b) + player(b, a)


from collections import Counter

def work_on_strings(a, b):
	(sa, sb) = (''.join((x + x.upper() for (x, y) in Counter(s.lower()).items() if y % 2)) for s in (a, b))
	return a.translate(str.maketrans(sb, sb.swapcase())) + b.translate(str.maketrans(sa, sa.swapcase()))


work_on_strings = lambda a, b: ''.join([elema if b.lower().count(elema.lower()) % 2 == 0 else elema.swapcase() for elema in a]) + ''.join([elemb if a.lower().count(elemb.lower()) % 2 == 0 else elemb.swapcase() for elemb in b])


def work_on_strings(a, b):
	corA = ''
	corB = ''
	lettersA = {}
	lettersB = {}
	for ia in a.lower():
		lettersA[ia] = a.lower().count(ia)
	for ib in b.lower():
		lettersB[ib] = b.lower().count(ib)
	for let in a:
		if let in lettersB.keys() and lettersB[let] % 2 != 0:
			corA += let.swapcase()
		elif let.isupper() == True and let.lower() in lettersB.keys():
			if lettersB[let.lower()] % 2 != 0:
				corA += let.lower()
			elif lettersB[let.lower()] % 2 == 0:
				corA += let.upper()
		else:
			corA += let
	for let in b:
		if let in lettersA.keys() and lettersA[let] % 2 != 0:
			corB += let.swapcase()
		elif let.isupper() == True and let.lower() in lettersA.keys():
			if lettersA[let.lower()] % 2 != 0:
				corB += let.lower()
			elif lettersA[let.lower()] % 2 == 0:
				corB += let.upper()
		else:
			corB += let
	return corA + corB


def work_on_strings(a, b):
	z = []
	for i in a:
		x = i
		for j in b:
			if i.upper() == j or i.lower() == j:
				x = x.swapcase()
		z.append(x)
	k = []
	for i in b:
		x = i
		for j in a:
			if i.upper() == j or i.lower() == j:
				x = x.swapcase()
		k.append(x)
	return ''.join(z) + ''.join(k)


def swapping(fir, sec):
	sf = set(fir)
	for ch in sf:
		occurs = fir.count(ch)
		if occurs % 2 != 0 and ch in sec.lower():
			f = f'{ch}{ch.upper()}'
			s = f'{ch.upper()}{ch}'
			t = sec.maketrans(f, s)
			sec = sec.translate(t)
	return sec

def work_on_strings(a, b):
	return swapping(b.lower(), a) + swapping(a.lower(), b)


from collections import Counter

def swap(s1, s2):
	temp = [('', '')] + [(f'{k}{k.upper()}', f'{k.upper()}{k}') for (k, v) in Counter(s1.lower()).items() if v & 1]
	return s2.translate(str.maketrans(*map(''.join, zip(*temp))))

def work_on_strings(a, b):
	return swap(b, a) + swap(a, b)