It's March and you just can't seem to get your mind off brackets. However, it is not due to basketball. You need to extract statements within strings that are contained within brackets.

You have to write a function that returns a list of statements that are contained within brackets given a string. If the value entered in the function is not a string, well, you know where that variable should be sitting.

Good luck!

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def bracket_buster(string):
	

Solutions:
import re
REGEX = re.compile('\\[(.*?)\\]')

def bracket_buster(strng):
	try:
		return REGEX.findall(strng)
	except TypeError:
		return 'Take a seat on the bench.'


from re import findall

def bracket_buster(s):
	return 'Take a seat on the bench.' if type(s) is not str else findall('\\[(.*?)\\]', s)


brackets = __import__('re').compile('\\[(.*?)\\]').findall

def bracket_buster(string):
	return brackets(string) if type(string) == str else 'Take a seat on the bench.'


import re

def bracket_buster(string):
	if not isinstance(string, str):
		return 'Take a seat on the bench.'
	return re.findall('\\[(.*?)\\]', string)


import re

def bracket_buster(string):
	return re.findall('\\[(.*?)\\]', string) if type(string) == str else 'Take a seat on the bench.'


import re

def bracket_buster(s):
	return re.findall('\\[(.*?)\\]', s) if isinstance(s, str) else 'Take a seat on the bench.'


import re

def bracket_buster(string):
	if type(string) is not str:
		return 'Take a seat on the bench.'
	return re.findall('\\[(.*?)\\]', string)


from re import findall as f
bracket_buster = lambda s: f('\\[(.*?)\\]', s) if isinstance(s, str) else 'Take a seat on the bench.'


import re

def bracket_buster(x):
	if type(x) != str:
		return 'Take a seat on the bench.'
	pat = '\\[.*?\\]'
	results = [match[1:-1] for match in re.findall(pat, str(x))]
	if len(results) == 0:
		return 'Take a seat on the bench.'
	else:
		return results


def bracket_buster(string):
	if string == None or not isinstance(string, str):
		return 'Take a seat on the bench.'
	import re
	pattern = re.compile("\\[([\\w\\s\\'?!\\d\\-]+|\\[{1,}|)\\]", re.I)
	mo = pattern.findall(string)
	return mo