# Description:

Remove the minimum number of exclamation marks from the start/end of each word in the sentence to make their amount equal on both sides.

### Notes:
* Words are separated with spaces
* Each word will include at least 1 letter
* There will be no exclamation marks in the middle of a word

___

## Examples

```
remove("Hi!") === "Hi"
remove("!Hi! Hi!") === "!Hi! Hi"
remove("!!Hi! !Hi!!") === "!Hi! !Hi!"
remove("!!!!Hi!! !!!!Hi !Hi!!!") === "!!Hi!! Hi !Hi!"
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def remove(s):
	

Solutions:
remove = lambda s: ' '.join((r for (r, _) in __import__('re').findall('((!*)\\w+\\2)', s)))


import re

def rm(word):
	left = len(re.search('^!*', word).group())
	right = len(re.search('!*$', word).group())
	ex = '!' * min(left, right)
	return ex + word.strip('!') + ex

def remove(s):
	return ' '.join(map(rm, s.split()))


import re

def remove(s):
	return ' '.join((m[0] for m in re.findall('((!*)\\w+\\2)', s)))


import re

def remove(stg):
	return ' '.join((re.sub('(!*)([^!]+)(!*)', equalize, word) for word in stg.split()))

def equalize(match):
	(before, word, after) = match.groups()
	shortest = min(before, after, key=len)
	return f'{shortest}{word}{shortest}'


import re

def remove(stg):
	words = stg.split(' ')
	for (i, group) in enumerate(words):
		(b, w, a) = re.search('(!*)([^!]+)(!*)', group).groups()
		s = min(a, b, key=len)
		words[i] = f'{s}{w}{s}'
	return ' '.join(words)


import re

def remove(s):
	li = []
	for i in s.split():
		start = re.search('^!+', i)
		end = re.search('!+$', i)
		i = re.sub('^!+', '', re.sub('!+$', '', i))
		m = min([len(start.group()) if start else 0, len(end.group()) if end else 0])
		li.append('!' * m + i + '!' * m)
	return ' '.join(li)


import re

def remove(s):
	return re.sub('(!*)([^! ]+)(!*)', repl, s)

def repl(m):
	s = '!' * min(map(len, (m[1], m[3])))
	return f'{s}{m[2]}{s}'


import re

def remove(s):
	return re.sub('!*?((!*)\\w+\\2)!*', '\\1', s)


def remove(s):
	tmp = s.split(' ')
	for (i, x) in enumerate(tmp):
		before = 0
		after = 0
		while x[0] == '!':
			before += 1
			x = x[1:]
		while x[-1] == '!':
			after += 1
			x = x[:-1]
		count = min(before, after)
		bangs = '!' * count
		tmp[i] = bangs + x + bangs
	return ' '.join(tmp)


def f(w):
	(l, r) = (0, 0)
	word = ''
	length = len(w)
	n = 0
	while n != length:
		if w[n] == '!':
			if not word:
				l += 1
			else:
				r += 1
		elif w[n].isalpha():
			word += w[n]
		n += 1
	return (l, r, word)

def remove(s):
	l = []
	for x in s.split():
		(a, b, word) = f(x)
		size = min(a, b)
		l.append(f"{'!' * size}{word}{'!' * size}")
	return ' '.join(l)