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!

Difficulty: introductory

Starter code:

def bracket_buster(string):
	

Solutions:
import re

REGEX = re.compile(r'\[(.*?)\]')


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(r'\[(.*?)\]', s)

brackets = __import__("re").compile(r"\[(.*?)\]").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(r'\[(.*?)\]', 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(r'\[(.*?)\]', 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(r'\[(.*?)\]', string)

from re import findall as f
bracket_buster=lambda s:f(r"\[(.*?)\]",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 = r'\[.*?\]'

    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):
    # Get after it!
    if string == None or not isinstance(string,str) : return "Take a seat on the bench."
    import re
    pattern = re.compile(r'\[([\w\s\'?!\d\-]+|\[{1,}|'')\]', re.I)
    mo =  pattern.findall(string)
    return mo