Write a function that removes every lone 9 that is inbetween 7s.

```python
seven_ate9('79712312') => '7712312'
seven_ate9('79797') => '777'
```

Input: String
Output: String

Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code:
def seven_ate9(str_):
	

Solutions:
def seven_ate9(str_):
	while str_.find('797') != -1:
		str_ = str_.replace('797', '77')
	return str_


import re

def seven_ate9(str_):
	return re.sub('79(?=7)', '7', str_)


def seven_ate9(str_):
	while '797' in str_:
		str_ = str_.replace('797', '77')
	return str_


def seven_ate9(str_):
	if '797' not in str_:
		return str_
	else:
		return seven_ate9(str_.replace('797', '77'))


import re

def seven_ate9(str_):
	return re.sub('(?<=7)9(?=7)', '', str_)


def seven_ate9(str_):
	return str_.replace('797', '77').replace('797', '77')


def seven_ate9(str_):
	(previous, current) = (str_, str_.replace('797', '77'))
	while previous != current:
		(previous, current) = (current, current.replace('797', '77'))
	return current


def seven_ate9(s):
	return ''.join(('' if x == '9' and s[y - 1:y + 2] == '797' else x for (y, x) in enumerate(s)))


def seven_ate9(str):
	while str.find('797') > -1:
		str = str.replace('797', '77')
	return str


def seven_ate9(s):
	return ''.join((s[i] for i in range(len(s)) if s[i - 1:i + 2] != '797'))


import re

def seven_ate9(s):
	return re.sub('(?<=7)9(?=7)', '', s)


seven_ate9 = lambda s: ''.join((x for (i, x) in enumerate(s) if s[i - 1:i + 2] != '797'))


seven_ate9 = lambda str_: str_.replace('797', 'Q').replace('Q', '77').replace('797', 'Q').replace('Q', '77')


import re
REGEXP = re.compile('79(?=7)')

def seven_ate9(str_):
	return REGEXP.sub('7', str_)

def seven_ate9(str_):
	while '797' in str_:
		str_ = str_.replace('797', '77')
	return str_


import re

def seven_ate9(str_):
	if '797' not in str_:
		return str_
	return seven_ate9(re.sub('7(9)7', '77', str_))


def seven_ate9(string):
	index = 0
	result = ''
	while index < len(string):
		if string[index] == '9':
			if index + 1 != len(string):
				if string[index - 1] == '7' and string[index + 1] == '7':
					result += ''
				else:
					result += string[index]
			else:
				result += string[index]
		else:
			result += string[index]
		index += 1
	return result


def seven_ate9(str_):
	str_ = list(str_)
	for i in range(len(str_) - 1):
		if str_[i] == '9':
			if str_[i - 1] == str_[i + 1] == '7':
				str_[i] = ''
	return ''.join(str_)


def seven_ate9(input):
	while '797' in input:
		position = input.find('797')
		input = input[0:position] + '77' + input[position + 3:]
	return input


def seven_ate9(str_):
	lst = []
	x = 0
	while len(str_) > x:
		if str_[x] == '9' and len(str_) > x + 1:
			if str_[x - 1] == '7' and str_[x + 1] == '7':
				x = x + 1
			else:
				lst.append(str_[x])
				x = x + 1
		else:
			lst.append(str_[x])
			x = x + 1
	return str(''.join(lst))


def seven_ate9(s):
	return s[0] + ''.join([s[i] for i in range(1, len(s) - 1) if not (s[i - 1] == '7' and s[i] == '9' and (s[i + 1] == '7'))]) + s[-1]


def seven_ate9(str):
	new = []
	for (i, v) in enumerate(str):
		if i == len(str) - 1:
			new.append(v)
		elif v == '9' and str[i - 1] == '7' and (str[i + 1] == '7'):
			pass
		else:
			new.append(v)
	return ''.join(new)


def seven_ate9(str_):
	for i in range(3):
		str_ = str_.replace('797', '77')
	return str_


def seven_ate9(str_):
	s = str_.replace('797', '77')
	return seven_ate9(s) if s != str_ else str_


def seven_ate9(str_):
	x = str_.replace('797', '77')
	while str_ != x:
		str_ = x
		x = str_.replace('797', '77')
	return str_


def seven_ate9(string):
	answ = []
	for (i, item) in enumerate(string):
		if i == 0 or i == len(string) - 1:
			answ.append(item)
		elif item == '9':
			if string[i - 1] == '7' and string[i + 1] == '7':
				continue
			else:
				answ.append(item)
		else:
			answ.append(item)
	return ''.join(answ)


from re import sub

def seven_ate9(str):
	return sub('79(?=7)', '7', str)


import re

def seven_ate9(str_):
	while str_ != re.sub('79+7', '77', str_):
		str_ = re.sub('797', '77', str_)
	return str_


def seven_ate9(str):
	str = str.replace('797', '77')
	return str.replace('797', '77')


def seven_ate9(str_):
	vals = list(str_)
	deletes = []
	for (idx, val) in enumerate(vals[1:-1], 1):
		if val == '9' and vals[idx - 1] == '7' and (vals[idx + 1] == '7'):
			deletes.append(idx)
	for value in reversed(deletes):
		del vals[value]
	return ''.join(vals)


def seven_ate9(str_):
	res = list(str_)
	for i in range(len(str_)):
		if str_[i:i + 3] == '797':
			res[i + 1] = ''
	return ''.join(res)


def seven_ate9(x):
	i = 0
	new_list = ''
	while i < len(x):
		n_slice = x[i:i + 3]
		if n_slice == '797':
			new_list = new_list + '7'
			i += 2
		else:
			new_list = new_list + x[i]
			i += 1
	return new_list


def seven_ate9(s):
	s = s.replace('797', '77')
	if '797' in s:
		return seven_ate9(s)
	return s


def seven_ate9(original_string):
	new_string = ''
	i = 0
	while i < len(original_string):
		current_character = original_string[i]
		current_slice = original_string[i:i + 3]
		if current_slice == '797':
			new_string = new_string + '7'
			i += 2
		else:
			new_string = new_string + current_character
			i += 1
	return new_string


def seven_ate9(str_):
	ls = [x for x in str_]
	counter = 1
	while counter < len(ls) - 1:
		if ls[counter] == '9' and ls[counter - 1] == '7' and (ls[counter + 1] == '7'):
			ls.pop(counter)
		counter += 1
	return ''.join(ls)


def seven_ate9(str_):
	res = list(str_)
	for i in range(len(str_) - 2, 0, -1):
		if res[i] == '9' and res[i + 1] == res[i - 1] == '7':
			res.pop(i)
	return ''.join(res)


def seven_ate9(str_):
	lst = list(str_)
	cursor = 1
	while cursor < len(lst) - 1:
		if lst[cursor] == '9' and lst[cursor - 1] == '7' and (lst[cursor + 1] == '7'):
			lst[cursor] = None
		cursor += 1
	return ''.join([item for item in lst if item])


def seven_ate9(str_):
	s_pattern = '797'
	r_pattern = '77'
	while s_pattern in str_:
		str_ = str_.replace(s_pattern, r_pattern)
	return str_


def seven_ate9(txt):
	count = 0
	txt = list(txt)
	removeable = []
	for i in range(len(txt)):
		try:
			if txt[i - 1] == '7':
				if txt[i] == '9':
					if txt[i + 1] == '7':
						(txt[i - 1], txt[i], txt[i + 1]) = ('7', '', '7')
		except IndexError:
			continue
	for i in txt:
		if i in removeable:
			txt.remove(txt[i])
	return ''.join(txt)


def seven_ate9(s):
	s2 = s[0]
	for (i, v) in enumerate(s[1:], 1):
		try:
			if s[i - 1] == s[i + 1] == '7' and v == '9':
				continue
			else:
				s2 += v
		except:
			break
	return s2 + s[-1]


def seven_ate9(str_):
	str_list = list(str_)
	new_list = []
	new_list.append(str_list[0])
	for i in range(1, len(str_list) - 1):
		if str_list[i] == '9':
			if str_list[i + 1] == '7' and str_list[i - 1] == '7':
				continue
			else:
				new_list.append(str_list[i])
		if str_list[i] != '9':
			new_list.append(str_list[i])
	new_list.append(str_list[-1])
	return ''.join(new_list)


def seven_ate9(str_):
	print(str_)
	s = str_.replace('797', '77')
	return s.replace('797', '77')


def seven_ate9(str_):
	str1_ = ''
	while str_ != str1_:
		str1_ = str_
		str_ = str1_.replace('797', '77', 1)
	return str_


def seven_ate9(s):
	result = ''
	for (i, c) in enumerate(s):
		if s[i - 1:i + 2] != '797':
			result += c
	return result


def seven_ate9(str_):
	for x in range(len(str_)):
		str_ = str_.replace('797', '77')
	return str_


def seven_ate9(s):
	while s.count('797') != 0:
		s = s.replace('797', '77')
	return s


def seven_ate9(s):
	res = ''
	i = 0
	while i < len(s):
		res += s[i]
		i += 1 + (i + 2 < len(s) and s[i:i + 3] == '797')
	return res


def seven_ate9(str_):
	output = str_[0]
	for i in range(1, len(str_) - 1):
		if not (str_[i - 1] == '7' and str_[i] == '9' and (str_[i + 1] == '7')):
			output += str_[i]
	return output + str_[-1]


def seven_ate9(str_):
	fag = str_.replace('797', '77')
	fuck = fag.replace('797', '77')
	return fuck


def seven_ate9(str_):
	i = 0
	length = len(str_)
	while i < length - 1:
		if str_[i] == '9' and str_[i - 1] == '7' and (str_[i + 1] == '7'):
			str_ = str_[:i] + str_[i + 1:]
			length -= 1
		i += 1
	return str_


from re import compile
r = compile('79(?=7)')

def seven_ate9(s: str) -> str:
	return r.sub('7', s)


def seven_ate9(str_):
	while True:
		if '797' in str_:
			str_ = str_.replace('797', '77', 1)
		else:
			return str_


seven_ate9 = lambda s: s[0] + ''.join((s[i + 1] for i in range(len(s) - 2) if s[i + 1] != '9' or s[i] + s[i + 2] != '77')) + s[-1]


def seven_ate9(str):
	for i in range(str.count('9')):
		str = str.replace('797', '77')
	return str


import re

def seven_ate9(number):
	number = re.sub('797', '77', number)
	return re.sub('797', '77', number)


import re

def seven_ate9(str_):
	replacedString = ''
	while True:
		replacedString = re.sub('797', '77', str_)
		if replacedString == str_:
			return replacedString
		str_ = replacedString


def seven_ate9(str_):
	counter = 0
	while counter <= str_.count('797'):
		str_ = str_.replace('797', '77')
		counter += 1
	return str_


def seven_ate9(str_):
	res = ''
	for (i, x) in enumerate(str_):
		if x != '9' or i == 0 or i == len(str_) - 1:
			res += f'{x}'
		elif str_[i - 1] != '7' or str_[i + 1] != '7':
			res += f'{x}'
	return res


import re

def seven_ate9(s):
	s = re.sub('797', '77', s)
	return re.sub('797', '77', s)


def seven_ate9(s):
	while s.find('797') != -1:
		s = s.replace('797', '77')
	return s


def seven_ate9(str_):
	txt = ''
	print(str_)
	for (index, letter) in enumerate(str_):
		if index == 0 or index + 1 == len(str_):
			txt += letter
			continue
		elif str_[index - 1] == '7' and str_[index + 1] == '7' and (letter is '9'):
			continue
		txt += letter
	return txt


import re

def seven_ate9(num):
	return re.sub('(?<=7)(9)(?=7)', '', num)


def seven_ate9(string):
	array = [s for s in string]
	for i in range(len(array) - 2):
		if array[i] == '7' and array[i + 1] == '9' and (array[i + 2] == '7'):
			array[i + 1] = None
	array = [x for x in array if x]
	return ''.join(array)


def seven_ate9(str_):
	new_strng = ''
	for (i, e) in enumerate(str_[:-1]):
		try:
			if e != '9':
				new_strng += e
			elif i == 0:
				new_strng += e
			elif str_[i - 1] != '7' or str_[i + 1] != '7':
				new_strng += e
		except IndexError:
			continue
	new_strng += str_[-1]
	return new_strng


def seven_ate9(sInput):
	lst = list(sInput)
	res = ''
	for i in range(len(lst) - 1):
		if not (i and lst[i] == '9' and (lst[i - 1] == '7') and (lst[i + 1] == '7')):
			res += lst[i]
	res += lst[len(lst) - 1]
	return res


def seven_ate9(str_):
	removals = []
	for i in range(len(str_) - 2):
		if str_[i] == '7' and str_[i + 1] == '9' and (str_[i + 2] == '7'):
			removals.append(i + 1)
	str_ = list(str_)
	for index in sorted(removals, reverse=True):
		del str_[index]
	return ''.join(str_)


def seven_ate9(str_):
	return ''.join(('' if str_[i] == '9' and str_[i - 1] == '7' and (str_[i + 1] == '7') else str_[i] for i in range(len(str_) - 1))) + str_[-1]


def seven_ate9(s):
	res = s[0]
	for (i, c) in enumerate(s[1:-1]):
		if c == '9' and s[i] == '7' and (s[i + 2] == '7'):
			pass
		else:
			res += c
	res += s[-1]
	return res


def seven_ate9(str_):
	for a in range(5):
		str_ = str_.replace('797', '77')
	return str_


def seven_ate9(str_):
	while '797' in str_:
		i9 = str_.find('797')
		str_ = str_[:i9 + 1] + str_[i9 + 2:]
	return str_


def seven_ate9(str_):
	return str_[0] + ''.join([c for (i, c) in enumerate(str_[1:-1], 1) if not (c == '9' and str_[i - 1] == str_[i + 1] == '7')]) + str_[-1]


def seven_ate9(str_in):
	if len(str_in) < 3:
		return str_in
	str_out = str_in[0]
	for (i, c) in enumerate(str_in[1:-1], 1):
		if c == '9':
			if str_in[i - 1] == '7' and str_in[i + 1] == '7':
				continue
		str_out += c
	return str_out + str_in[-1]


def seven_ate9(str_):
	ans = str_[0]
	for i in range(1, len(str_) - 1):
		if str_[i] == '9' and str_[i - 1] == '7' and (str_[i + 1] == '7'):
			continue
		ans += str_[i]
	return ans + str_[-1]


def seven_ate9(str_):
	return ''.join((k for (i, k) in enumerate(str_) if str_[i - 1:i + 2] != '797'))


seven_ate9 = s9 = lambda s: s9(s.replace('797', '77')) if s.count('797') else s


import re
rx = re.compile('(?<=7)9(?=7)')

def seven_ate9(str_):
	return rx.sub('', str_)


def seven_ate9(s):
	s = s.replace('797', '77').replace('797', '77')
	return s


def seven_ate9(str_):
	res = str_[0]
	for i in range(1, len(str_) - 1):
		if str_[i - 1] == '7' and str_[i + 1] == '7' and (str_[i] == '9'):
			continue
		else:
			res += str_[i]
	return res + str_[-1]


def seven_ate9(x):
	x = x.replace('797', '77')
	x = x.replace('797', '77')
	return x


import re

def seven_ate9(str_):
	str_ = re.sub('797', '77', str_)
	return re.sub('797', '77', str_)


import re

def seven_ate9(str_):
	while '797' in str_:
		str_ = str_.replace('797', '77')
	return str_


import re
seven_ate9 = lambda s: re.sub('(?:7)(9)(?=7)', '7', s)