def shortestDistance(words, word1, word2):
dist = float('inf')
i, d1, d2 = 0, None, None
while i<len(words):
if words[i]==word1:
d1=i
elif words[i]==word2:
d2=i
if d1 is not None and d2 is not None:
dist = min(dist,abs(d1-d2))
i+=1
return dist
words = ['hhh','lll','iii']
print(shortestDistance(words,'hhh','iii'))