An array is called `zero-balanced` if its elements sum to `0` and for each positive element `n`, there exists another element that is the negative of `n`. Write a function named `ìsZeroBalanced` that returns `true` if its argument is `zero-balanced` array, else return `false`. Note that an `empty array` will not sum to `zero`.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def is_zero_balanced(arr):
	

Solutions:
from collections import Counter

def is_zero_balanced(arr):
	c = Counter(arr)
	return bool(arr) and all((c[k] == c[-k] for k in c))


def is_zero_balanced(arr):
	return all(arr) == sum(arr) == 0


def is_zero_balanced(arr):
	return arr != [] and sum(arr) == 0 and all((-x in arr for x in arr))


def is_zero_balanced(arr):
	return False if not 0 in arr else not sum(arr)


def is_zero_balanced(arr):
	pos = (n for n in arr if n > 0)
	neg = (-n for n in arr if n < 0)
	return sorted(pos) == sorted(neg) if arr else False


def is_zero_balanced(arr):
	return all((arr.count(i) == arr.count(-i) for i in arr)) if arr else False


def is_zero_balanced(arr):
	return bool(arr) and sum(arr) == 0 and all((-x in arr for x in arr if x > 0))


from collections import Counter

def is_zero_balanced(arr):
	if not arr:
		return False
	arr = Counter(arr)
	for element in arr:
		if not arr[element] == arr[-element]:
			return False
	return True


def is_zero_balanced(a):
	p = sorted((abs(e) for e in a if e > 0))
	n = sorted((abs(e) for e in a if e < 0))
	return all((x == y for (x, y) in zip(p, n))) and len(p) == len(n) and (len(a) > 0)