I have a problem for class where I need to compare strings ie. 'truck' vs 'trunk' and return the FIRST position in which the strings differ. I have managed to solve the initial part but I run into trouble when I encounter strings of different lengths ie. 'truck' vs 'trucks'. I've tried a few different methods before deleting and going back to square 1 so I'm hoping to get some advice here. Any help would be greatly appreciated. My current code is below.
IDENTICAL = -1
def singleline_diff(line1, line2):
short = min(len(line1),len(line2))
for i in range(0,short):
if line1[i] == line2[i]:
continue
else:
return i
else:
return IDENTICAL
word1 = 'truck'
word2 = 'trunk'
prob1 = singleline_diff(word1, word2)
print(prob1)