Given a mixed array of number and string representations of integers, add up the string integers and subtract this from the total of the non-string integers. 

Return as a number.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Starter code: def div_con(x):
	

Solutions:
def div_con(lst):
	return sum((n if isinstance(n, int) else -int(n) for n in lst))


def div_con(x):
	return sum([a for a in x if isinstance(a, int)]) - sum([int(a) for a in x if not isinstance(a, int)])


def div_con(x):
	integer = []
	string = []
	for element in x:
		if type(element) == int:
			integer.append(element)
		else:
			string.append(int(element))
	return sum(integer) - sum(string)


def div_con(x):
	sum = 0
	for i in x:
		if type(i) == int:
			sum += i
		else:
			sum -= int(i)
	return sum


def div_con(x):
	return sum((-int(i) if isinstance(i, str) else i for i in x))


def div_con(x):
	diff = 0
	for num in x:
		if isinstance(num, int):
			diff += num
		else:
			diff -= int(num)
	return diff


div_con = lambda l: sum((e if type(e) == int else -int(e) for e in l))


def div_con(x):
	num = 0
	strnum = 0
	for number in x:
		if int(number) == number:
			num = num + number
		else:
			strnum = strnum + int(number)
	num = num - strnum
	return num


div_con = lambda x: sum((i for i in x if type(i) == int)) - sum((int(s) for s in x if type(s) == str))