# altERnaTIng cAsE <=> ALTerNAtiNG CaSe

Define `String.prototype.toAlternatingCase` (or a similar function/method *such as* `to_alternating_case`/`toAlternatingCase`/`ToAlternatingCase` in your selected language; **see the initial solution for details**) such that each lowercase letter becomes uppercase and each uppercase letter becomes lowercase. For example:
``` haskell
toAlternatingCase "hello world" `shouldBe` "HELLO WORLD"
toAlternatingCase "HELLO WORLD" `shouldBe` "hello world"
toAlternatingCase "hello WORLD" `shouldBe` "HELLO world"
toAlternatingCase "HeLLo WoRLD" `shouldBe` "hEllO wOrld"
toAlternatingCase "12345"       `shouldBe` "12345"
toAlternatingCase "1a2b3c4d5e"  `shouldBe` "1A2B3C4D5E"
```
```C++
string source = "HeLLo WoRLD";
string upperCase = to_alternating_case(source);
cout << upperCase << endl; // outputs: hEllO wOrld
```
As usual, your function/method should be pure, i.e. it should **not** mutate the original string.

Difficulty: EASY
Starter code: def to_alternating_case(string):
	

Solutions:
def to_alternating_case(string):
	return string.swapcase()


def to_alternating_case(string):
	return ''.join([c.upper() if c.islower() else c.lower() for c in string])


to_alternating_case = str.swapcase


def to_alternating_case(string):
	strn = ''
	for i in string:
		if i.isupper():
			strn += i.lower()
		else:
			strn += i.upper()
	return strn


def to_alternating_case(string):
	capital_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
	lowercase_letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	new_string = []
	for character in string:
		if character in capital_letters:
			new_string.append(lowercase_letters[capital_letters.index(character)])
		if character in lowercase_letters:
			new_string.append(capital_letters[lowercase_letters.index(character)])
		if character not in capital_letters and character not in lowercase_letters:
			new_string.append(character)
	return ''.join(new_string)


def to_alternating_case(string):
	new_string = ''
	for char in string:
		if char.isupper():
			new_string += char.lower()
		else:
			new_string += char.upper()
	return new_string


def to_alternating_case(string):
	return ''.join((string[i].upper() if string[i].islower() else string[i].lower() for i in range(len(string))))


def to_alternating_case(string):
	s = ''
	for i in string:
		i.split()
		if i.islower():
			s = s + i.upper()
		if i.isupper():
			s = s + i.lower()
		if i.isspace():
			s = s + ' '
		if i.isdigit():
			s = s + str(i)
		if i == '.':
			s = s + str('.')
		if i == '<':
			s = s + str('<')
		if i == '=':
			s = s + str('=')
		if i == '>':
			s = s + str('>')
		if i == "'":
			s = s + str("'")
		if i == '?':
			s = s + str('?')
		if i == ';':
			s = s + str(';')
		if i == ',':
			s = s + str(',')
		if i == '/':
			s = s + str('/')
		if i == "'":
			s = s + str("'")
		if i == '|':
			s = s + str('|')
		if i == '!':
			s = s + str('!')
		if i == ':':
			s = s + str(':')
	return s


to_alternating_case = lambda s: s.swapcase()


import string

def to_alternating_case(s):
	ans = ''
	for c in s:
		if c in string.ascii_lowercase:
			ans += c.upper()
		elif c in string.ascii_uppercase:
			ans += c.lower()
		else:
			ans += c
	return ans


def to_alternating_case(string):
	string_2 = ''
	for char in string:
		if char.islower():
			string_2 += char.upper()
		else:
			string_2 += char.lower()
	return string_2


def to_alternating_case(string):
	res = []
	for i in list(string):
		if i.isupper():
			res.append(i.lower())
		else:
			res.append(i.upper())
	return ''.join(res)


import re

def to_alternating_case(string):
	return re.sub('([a-z])|([A-Z])', lambda c: (c.groups()[0] or '').upper() + (c.groups()[1] or '').lower(), string)


def to_alternating_case(string):
	new_str = ''
	for char in string:
		if char.isupper() == True:
			new_str += char.lower()
		else:
			new_str += char.upper()
	return new_str


def to_alternating_case(string):
	return ''.join([i.capitalize() if str.islower(i) else i.lower() for i in string])


def to_alternating_case(string):
	temp = ''
	for i in string:
		if ord(i) >= 65 and ord(i) <= 90:
			temp += chr(ord(i) + 32)
		elif ord(i) >= 97 and ord(i) <= 122:
			temp += chr(ord(i) - 32)
		else:
			temp += i
	return temp


def to_alternating_case(string):
	return ''.join(map(lambda a: a.lower() if a.isupper() else a.upper(), string))


def to_alternating_case(string):
	NewString = []
	for stri in string:
		if type(stri) is str:
			NewString.append(stri.upper() if stri.islower() else stri.lower())
		else:
			NewString.append(stri)
	return ''.join(NewString)


def to_alternating_case(string):
	str1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
	str2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
	return string.translate(str.maketrans(str1, str2))


def to_alternating_case(string):
	return ''.join((i.swapcase() for i in string))


def to_alternating_case(string):
	a = ''
	for i in string:
		if i == i.upper():
			a += i.lower()
		else:
			a += i.upper()
	return a


def to_alternating_case(string):
	strX = ''
	for i in range(len(string)):
		if string[i].isupper():
			strX += string[i].lower()
		elif string[i].islower():
			strX += string[i].upper()
		else:
			strX += string[i]
	return strX


def to_alternating_case(string):
	fs = ''
	for x in string:
		if x.isupper():
			fs += x.lower()
		else:
			fs += x.upper()
	return fs


def to_alternating_case(string):
	altstring = ''
	for i in range(len(string)):
		if string[i] == string[i].lower():
			altstring += string[i].upper()
		else:
			altstring += string[i].lower()
	return altstring


def to_alternating_case(string):
	alter_case = lambda let: let.lower() if let.isupper() else let.upper()
	return ''.join(map(alter_case, string))


def to_alternating_case(string):
	alternate = ''
	for char in string:
		if char == char.upper():
			alternate += char.lower()
		else:
			alternate += char.upper()
	return alternate


def to_alternating_case(string):
	res = []
	for token in string:
		if token.isupper():
			res.append(token.lower())
		elif token.islower():
			res.append(token.upper())
		else:
			res.append(token)
	return ''.join(res)


def to_alternating_case(s):
	n = s.swapcase()
	return n


def to_alternating_case(string):
	output = ''
	for character in string:
		if character.isupper():
			output += character.lower()
		else:
			output += character.upper()
	return output


def to_alternating_case(string):
	str2 = ''
	for char in string:
		if char.isalpha():
			if char.islower():
				r = char.upper()
				str2 += r
			else:
				r = char.lower()
				str2 += r
		else:
			str2 += char
	return str2


def to_alternating_case(string):
	x = list(string)
	c = ''
	for k in x:
		if k == k.upper():
			c += k.lower()
		elif k == k.lower():
			c += k.upper()
		else:
			c += k
	return c


def to_alternating_case(string):
	result = ''
	for char in string:
		if char.islower() == True:
			result += char.upper()
		else:
			result += char.lower()
	return result


import string as str

def to_alternating_case(string):
	res = ''
	for i in string:
		if i in str.ascii_lowercase:
			res += i.upper()
		elif i in str.ascii_uppercase:
			res += i.lower()
		else:
			res += i
	return res


def to_alternating_case(string):
	strn = ''
	for i in string:
		if i == i.upper():
			strn += i.lower()
		elif i == i.lower():
			strn += i.upper()
	return strn


def to_alternating_case(string):
	return string.translate(str.maketrans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'))


def to_alternating_case(s):
	return s.swapcase()


def to_alternating_case(s):
	return ''.join((c.upper() if c.islower() else c.lower() if c.isupper() else c for c in s))


def to_alternating_case(string):
	result = ''
	lower_vowels = 'abcdefghijklmnopqrstuvwxyz'
	upper_vowels = lower_vowels.upper()
	index = 0
	while index < len(string):
		if string[index] in lower_vowels:
			result += string[index].upper()
		elif string[index] in upper_vowels:
			result += string[index].lower()
		else:
			result += string[index]
		index += 1
	return result


def to_alternating_case(string):
	result = ''
	for i in string:
		for j in i:
			if j.islower():
				cap = j.upper()
				result = result + cap
			else:
				small = j.lower()
				result = result + small
	return result


to_alternating_case = lambda string: ''.join([[i.upper(), i.lower()][i.isupper()] for i in string])


def to_alternating_case(string):
	empty_string = ''
	for i in string:
		if i.islower():
			empty_string = empty_string + i.upper()
		else:
			empty_string = empty_string + i.lower()
	return empty_string


def to_alternating_case(string):
	a = ''
	for n in string:
		if n.isupper():
			a += n.lower()
		elif n.islower():
			a += n.upper()
		else:
			a += n
	return a


def to_alternating_case(string):
	result = ''
	for c in string:
		if c == c.upper():
			result = result + c.lower()
		else:
			result = result + c.upper()
	return result


def to_alternating_case(s):
	alt = ''
	for i in range(len(str(s))):
		if s[i].islower():
			alt += s[i].upper()
		else:
			alt += s[i].lower()
	return alt


def to_alternating_case(s: str) -> str:
	my_str = ''
	for i in s:
		if i.islower():
			my_str += i.upper()
		elif i.isupper():
			my_str += i.lower()
		else:
			my_str += i
	return my_str


def to_alternating_case(string):
	s = ''
	for l in string:
		if l == l.upper():
			l = l.lower()
			s += l
		else:
			l = l.upper()
			s += l
	return s


def to_alternating_case(string):
	res = ''
	for l in string:
		if l.isupper():
			l = l.lower()
			res += l
		elif l.islower():
			l = l.upper()
			res += l
		else:
			res += l
	return res


def to_alternating_case(string):
	answer = ''
	for c in string:
		if c.isupper():
			answer += c.lower()
		elif c.islower():
			answer += c.upper()
		else:
			answer += c
	return answer


def to_alternating_case(string):
	ans = ''
	for i in string:
		if i == i.lower():
			ans += i.upper()
		else:
			ans += i.lower()
	return ans


def to_alternating_case(string):
	result = ''
	for i in string:
		if i.isupper():
			result += i.lower()
		if i.islower():
			result += i.upper()
		elif i == ' ':
			result += i
		elif i.isalpha() == False:
			result += i
	return result


def to_alternating_case(string):
	out = ''
	for s in string:
		if s.islower():
			out += s.upper()
		elif s.isupper():
			out += s.lower()
		else:
			out += s
	return out


def to_alternating_case(string):
	output = ''
	for i in string:
		if i == i.lower():
			output += i.upper()
		else:
			output += i.lower()
	return output


def to_alternating_case(string):
	l = []
	for i in string:
		if i.upper() == i:
			l.append(i.lower())
		else:
			l.append(i.upper())
	return ''.join(l)


def to_alternating_case(string):
	result = ''
	for i in range(len(string)):
		ascii_code = ord(string[i])
		if 97 <= ascii_code <= 122:
			ascii_code -= 32
		elif 65 <= ascii_code <= 90:
			ascii_code += 32
		result += chr(ascii_code)
	return result


def to_alternating_case(string):
	for char in string:
		a = string.swapcase()
	return a
print(to_alternating_case('cIao'))


def to_alternating_case(string):
	return ''.join(list(map(lambda s: s.lower() if s.isupper() else s.upper(), string)))


def to_alternating_case(string):
	list1 = []
	for letter in string:
		if letter.isupper():
			list1.append(letter.lower())
		else:
			list1.append(letter.upper())
	alt_string = ''.join(list1)
	return alt_string


def to_alternating_case(string):
	output = ''
	for str in string:
		if str.isupper():
			output += str.lower()
		elif str.islower():
			output += str.upper()
		elif str == ' ':
			output += ' '
		else:
			output += str
	return output


import string

def to_alternating_case(str):
	return ''.join((c.lower() if c in string.ascii_uppercase else c.upper() for c in str))


def to_alternating_case(string):
	return ''.join([letter.swapcase() for letter in string])


def to_alternating_case(string):
	word = ''
	for el in string:
		if el == el.upper():
			word += el.lower()
		elif el == el.lower():
			word += el.upper()
		else:
			word += el.upper()
	return word


def to_alternating_case(string):
	x = []
	for i in list(string):
		if i.isupper():
			x.append(i.lower())
		elif i.isspace():
			x.append(' ')
		else:
			x.append(i.upper())
	return ''.join(x)


to_alternating_case = lambda string: ''.join(map(lambda x: x.upper() if x.islower() else x.lower(), string))


def to_alternating_case(string):
	resultStr = ''
	for k in string:
		if k.islower():
			resultStr += k.upper()
		elif k.isupper():
			resultStr += k.lower()
		else:
			resultStr += k
	return resultStr


def to_alternating_case(string):
	string2 = ''
	for i in string:
		if i.upper() == i:
			string2 += i.lower()
		else:
			string2 += i.upper()
	return string2


def to_alternating_case(string):
	soln = ''
	for char in string:
		if char == char.lower():
			soln += char.upper()
		elif char == char.upper():
			soln += char.lower()
		elif char == '':
			soln += char
	return soln


def to_alternating_case(string):
	e = []
	for i in string:
		if ord(i) >= 65 and ord(i) <= 90:
			a = i.lower()
			e.append(a)
		else:
			a = i.upper()
			e.append(a)
	finale = ''
	nuova = finale.join(e)
	return nuova


def to_alternating_case(string):
	new = []
	for letter in string:
		if letter.isupper():
			new.append(letter.lower())
		elif letter.islower():
			new.append(letter.upper())
		else:
			new.append(letter)
	return ''.join(new)


def to_alternating_case(s):
	new_line = ''
	for a in s:
		if a.isupper():
			new_line += a.lower()
		elif a.islower():
			new_line += a.upper()
		else:
			new_line += a
	return new_line


def to_alternating_case(s):
	return str().join([i.lower() if i.isupper() else i.upper() for i in s])


def to_alternating_case(string):
	return ''.join(list(map(lambda char: char.upper() if char.islower() else char.lower(), string)))


def to_alternating_case(string):
	newword = ''
	for i in range(len(string)):
		if string[i].isupper() == True:
			newword += string[i].lower()
		elif string[i].islower() == True:
			newword += string[i].upper()
		else:
			newword += string[i]
	return newword


def to_alternating_case(string):
	res = ''
	for char in string:
		if char.isalpha():
			res += char.upper() if not char.isupper() else char.lower()
		else:
			res += char
	return res


def to_alternating_case(string):
	new_string = []
	for character in string:
		if character.isalpha():
			if character.islower():
				new_string.append(character.upper())
			elif character.isupper():
				new_string.append(character.lower())
		else:
			new_string.append(character)
	return ''.join(new_string)


def to_alternating_case(string):
	return ''.join((i.upper() if i == i.casefold() else i.casefold() for i in string))


def to_alternating_case(string):
	final = ''
	for i in string:
		if i == i.lower():
			final += i.upper()
		else:
			final += i.lower()
	return final


A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
e = A.lower()

def to_alternating_case(s):
	t = []
	for i in s:
		if i in A:
			t.append(i.lower())
		elif i in e:
			t.append(i.upper())
		else:
			t.append(i)
	return ''.join(t)


def to_alternating_case(string):
	string = [i for i in string]
	for i in range(len(string)):
		if string[i].isupper():
			string[i] = string[i].lower()
		elif string[i].islower():
			string[i] = string[i].upper()
	return ''.join(string)


def to_alternating_case(string):
	result = []
	for letter in string:
		if letter.upper() == letter:
			result.append(letter.lower())
		elif letter.lower() == letter:
			result.append(letter.upper())
	return ''.join(result)


def to_alternating_case(a):
	lst = []
	for i in a:
		if i == i.lower():
			lst.append(i.upper())
		else:
			lst.append(i.lower())
	return ''.join(lst)


def to_alternating_case(string):
	ret = []
	for char in string:
		if char.isupper():
			ret.append(char.lower())
		else:
			ret.append(char.upper())
	return ''.join(ret)