Create a program that will take in a string as input and, if there are duplicates of more than two alphabetical characters in the string, returns the string with all the extra characters in a bracket.
For example, the input "aaaabbcdefffffffg" should return  "aa[aa]bbcdeff[fffff]g" 
Please also ensure that the input is a string, and return "Please enter a valid string" if it is not.
def string_parse(string):
    if type(string)!=str:return "Please enter a valid string"
    try:
        out=string[:2]
        temp=''
        for i in string[2:]:
            if i==out[-1]==out[-2]:
                temp+=i
            else:
                if temp!='':out+='['+temp+']'
                out+=i
                temp=''
        if temp!='':out+='['+temp+']'
        return out
    except:
        return "Please enter a valid string"
        

def string_parse(string):
    if type(string)!=str:return "Please enter a valid string"
    try:
        out=string[:2]
        temp=''
        for i in string[2:]:
            if i==out[-1]==out[-2]:
                temp+=i
            else:
                if temp!='':out+='['+temp+']'
                out+=i
                temp=''
        if temp!='':out+='['+temp+']'
        return out
    except:
        return "Please enter a valid string"
        
