(pattern, string)
return backtrack(pattern, string, {})
:type pattern: str
    :type string: str
    :rtype: bool
:type pattern: str
    :type string: str
    :rtype: bool
: type pattern : str : type string : str : rtype : bool
def pattern_match(pattern, string):
    """
    :type pattern: str
    :type string: str
    :rtype: bool
    """
    def backtrack(pattern, string, dic):

        if len(pattern) == 0 and len(string) > 0:
            return False

        if len(pattern) == len(string) == 0:
            return True

        for end in range(1, len(string)-len(pattern)+2):
            if pattern[0] not in dic and string[:end] not in dic.values():
                dic[pattern[0]] = string[:end]
                if backtrack(pattern[1:], string[end:], dic):
                    return True
                del dic[pattern[0]]
            elif pattern[0] in dic and dic[pattern[0]] == string[:end]:
                if backtrack(pattern[1:], string[end:], dic):
                    return True
        return False

    return backtrack(pattern, string, {})
def pattern_match ( pattern , string ) : def backtrack ( pattern , string , dic ) : if len ( pattern ) == 0 and len ( string ) > 0 : return False if len ( pattern ) == len ( string ) == 0 : return True for end in range ( 1 , len ( string ) - len ( pattern ) + 2 ) : if pattern [ 0 ] not in dic and string [ : end ] not in dic . values ( ) : dic [ pattern [ 0 ] ] = string [ : end ] if backtrack ( pattern [ 1 : ] , string [ end : ] , dic ) : return True del dic [ pattern [ 0 ] ] elif pattern [ 0 ] in dic and dic [ pattern [ 0 ] ] == string [ : end ] : if backtrack ( pattern [ 1 : ] , string [ end : ] , dic ) : return True return False return backtrack ( pattern , string , { } )