# 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!"
```

Difficulty: introductory

Starter code:

def remove(s):
	

Solutions:
remove=lambda s:' '.join(r for r,_ in __import__('re').findall(r'((!*)\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(r'((!*)\w+\2)', s))

import re

def remove(stg):
    return " ".join(re.sub(r"(!*)([^!]+)(!*)", 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(r"(!*)([^!]+)(!*)", 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(r"!+$", i)
        i = re.sub(r"^!+", "", re.sub(r"!+$", "", 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(r'(!*)([^! ]+)(!*)', 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(r'!*?((!*)\w+\2)!*',r'\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)