<doocs>0245.Shortest Word Distance III_1.py
def shortestWordDistance( wordsDict: List[str], word1: str, word2: str) -> int:
    i1 = i2 = -1
    shortest_distance = len(wordsDict)
    same = word1 == word2
    for i in range(len(wordsDict)):
        if same:
            if word1 == wordsDict[i]:
                if i1 != -1:
                    shortest_distance = min(shortest_distance, i - i1)
                i1 = i
        else:
            if word1 == wordsDict[i]:
                i1 = i
            if word2 == wordsDict[i]:
                i2 = i
            if i1 != -1 and i2 != -1:
                shortest_distance = min(shortest_distance, abs(i1 - i2))
    return shortest_distance
def sample_funcname ( var_0 : List [ str ] , var_3 : str , var_4 : str ) -> int :
    var_8 = var_6 = - 1
    var_10 = len ( var_0 )
    var_11 = var_3 == var_4
    for var_13 in range ( len ( var_0 ) ) :
        if var_11 :
            if var_3 == var_0 [ var_13 ] :
                if var_8 != - 1 :
                    var_10 = min ( var_10 , var_13 - var_8 )
                var_8 = var_13
        else :
            if var_3 == var_0 [ var_13 ] :
                var_8 = var_13
            if var_4 == var_0 [ var_13 ] :
                var_6 = var_13
            if var_8 != - 1 and var_6 != - 1 :
                var_10 = min ( var_10 , abs ( var_8 - var_6 ) )
    return var_10
