#NEWLINE# def shortestWordDistance( self , words , word1 , word2 ) : #NEWLINE# #INDENT# dist = float ( 'inf' ) #NEWLINE# ( i , index1 , index2 ) = ( 0 , None , None ) #NEWLINE# while ( dist < len ( words ) ) : #NEWLINE# #INDENT# if ( words [ i ] == word1 ) : #NEWLINE# #INDENT# if ( index1 is not None ) : #NEWLINE# #INDENT# dist = min ( dist , abs ( ( index1 - i ) ) ) #NEWLINE# #UNINDENT# index1 = i #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( words [ i ] == word2 ) : #NEWLINE# #INDENT# index2 = i #NEWLINE# #UNINDENT# #UNINDENT# if ( ( index1 is not None ) and ( index2 is not None ) ) : #NEWLINE# #INDENT# dist = min ( dist , abs ( ( index1 - index2 ) ) ) #NEWLINE# #UNINDENT# i += 1 #NEWLINE# #UNINDENT# return dist