from functools import cmp_to_key

def comp(x, y):
	return x - y if arr.count(x) == arr.count(y) else arr.count(y) - arr.count(x)

arr = [7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1, 2, 2, 8, 5, 8, 8]

# Works because sorted is an iterable which doesn't modify the original array
print(sorted(arr, key = cmp_to_key(comp)))

# Broken because this sorts the array in-place
arr.sort(key = cmp_to_key(comp))
print(arr)