import re


def compact(text, strip=True, space=' '):
	"""
	Remove all repeating spaces and replace space with a single instance of
	the given (space) value.
	If strip is True, the string will also be striped.
	"""
	if strip:
		text = text.strip()
	return re.sub(' +', space, text)