【每日一题0917】匹配头尾

def compare(s1: str, s2: str) -> bool:
    if s1 == s2:
        return True

    if len(s1) >= len(s2) and "*" in s2:
        if len(s2) == 1:
            return True

        idx = s2.index("*")
        start_data = s2[:idx]
        if s2.startswith("*"):
            start_data = s1[0]

        end_data = s2[idx+1:]
        if s2.endswith("*"):
            end_data = s1[-1]

        if s1.startswith(start_data) and s1.endswith(end_data):
            return True

    return False

assert compare("abccd", "abccd") is True
assert compare("abccd", "abcd") is False
assert compare("abccd", "ab*d") is True
assert compare("abccd", "ab*cy") is False
def compare(s1: str, s2: str) -> bool:
    if '*' not in s2:
        if s2 == s1:
            return True
        else:
            return False
    else:
        value_list=s2.split('*')
        s_list=[]
        for i in value_list:
            try:
                s_list.append(s1.index(i))
            except:
                return False
        s1_list=[j for j in s_list]
        s_list.sort(reverse=False)
        if s_list==s1_list:
            return True
        else:
            return False

assert compare("abccd", "abccd") is True
assert compare("abccd", "abcd") is False
assert compare("abccd", "ab*d") is True
assert compare("abccd", "ab*cy") is False
assert compare("abccd", "cd*ab") is False