Remove the parentheses
=
In this kata you are given a string for example:

```python
"example(unwanted thing)example"
```

Your task is to remove everything inside the parentheses as well as the parentheses themselves.

The example above would return:

```python
"exampleexample"
```

Other than parentheses only letters and spaces can occur in the string. Don't worry about other brackets like ```"[]"``` and ```"{}"``` as these will never appear.

Difficulty: EASY
Starter code: def remove_parentheses(s):
	

Solutions:
def remove_parentheses(s):
	(lvl, out) = (0, [])
	for c in s:
		lvl += c == '('
		if not lvl:
			out.append(c)
		lvl -= c == ')'
	return ''.join(out)


import re

def remove_parentheses(s):
	while (t := re.sub('\\([^()]*\\)', '', s)) != s:
		s = t
	return s


def remove_parentheses(s):
	para = ('(', ')')
	stack = []
	string = []
	for char in s:
		if char in para:
			stack.append(char) if char == para[0] else stack.pop()
		elif len(stack) == 0:
			string.append(char)
	return ''.join(string)


import re

def remove_parentheses(s):
	(ret, count) = ('', 0)
	for letter in s:
		if letter == '(':
			count += 1
		elif letter == ')':
			count -= 1
		elif count == 0:
			ret += letter
	return ret


def remove_parentheses(s):

	def f():
		paren = 0
		for c in s:
			if c == '(':
				paren += 1
			elif c == ')':
				paren -= 1
			elif not paren:
				yield c
	return ''.join(f())


def remove_parentheses(s):
	nested = 0
	result = []
	for c in s:
		if c == '(':
			nested += 1
		elif c == ')':
			nested -= 1
		elif nested == 0:
			result.append(c)
	return ''.join(result)


def remove_parentheses(s):
	stack = []
	for i in range(len(s)):
		if s[i] is not ')':
			stack.append(s[i])
		else:
			while stack[-1] != '(':
				stack.pop()
			stack.pop()
	return ''.join(stack)


import re
P = re.compile('\\([^\\(\\)]*\\)')

def remove_parentheses(s):
	if '(' in s:
		return remove_parentheses(P.sub('', s))
	return s


import re
f = remove_parentheses = lambda s: f(re.sub('\\([^\\(\\)]*\\)', '', s)) if '(' in s else s


def remove_parentheses(s):
	s2 = s.replace('(', '|').replace(')', '|')
	level = 0
	start = 0
	i = s2.find('|')
	while i != -1:
		if s[i] == '(':
			if level == 0:
				start = i
			level += 1
		elif s[i] == ')':
			level -= 1
			if level == 0:
				s = s[0:start] + s[i + 1:]
				s2 = s2[0:start] + s2[i + 1:]
				i = -1
		i = s2.find('|', i + 1)
	return s
print(remove_parentheses('example(unwanted thing)example'))