A zero-indexed array ```arr``` consisting of n integers is given. The dominator of array ```arr``` is the value that occurs in more than half of the elements of ```arr```.
For example, consider array ```arr``` such that ```arr = [3,4,3,2,3,1,3,3]``` The dominator of ```arr``` is 3 because it occurs in 5 out of 8 elements of ```arr``` and 5 is more than a half of 8.
Write a function ```dominator(arr)``` that, given a zero-indexed array ```arr``` consisting of n integers, returns the dominator of ```arr```. The function should return −1 if array does not have a dominator. All values in ```arr``` will be >=0.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def dominator(arr):
	

Solutions:
def dominator(arr):
	for x in set(arr):
		if arr.count(x) > len(arr) / 2.0:
			return x
	return -1


from collections import Counter

def dominator(arr):
	if not arr:
		return -1
	(k, v) = Counter(arr).most_common(1)[0]
	return k if v > len(arr) / 2 else -1


dominator = lambda a: ([x for x in set(a) if a.count(x) > len(a) / 2][:1] or [-1])[0]


from collections import Counter

def dominator(arr):
	n = Counter(arr).most_common(1)
	return n[0][0] if n and n[0][1] > len(arr) // 2 else -1


def dominator(lst):
	if lst == []:
		return -1
	candidate = object()
	count = 0
	for elem in lst:
		if elem == candidate:
			count += 1
		elif count > 0:
			count -= 1
		else:
			candidate = elem
			count = 1
	if count > 0 and lst.count(candidate) > len(lst) // 2:
		return candidate
	else:
		return -1


from collections import Counter

def dominator(arr):
	xs = Counter(arr).most_common(1)
	if xs and xs[0][1] > len(arr) // 2:
		return xs[0][0]
	return -1


def dominator(arr):
	half_length = len(arr) / 2
	for e in arr:
		if arr.count(e) > half_length:
			return e
	return -1


from collections import Counter

def dominator(arr):
	[(e, c)] = Counter(arr).most_common(1) or [(-1, 0)]
	return [-1, e][2 * c > len(arr)]


def dominator(arr):
	for el in arr:
		if arr.count(el) > len(arr) / 2:
			return el
	return -1