Feb-12-2018, 06:10 PM
Alright, let's go without enumerate, then. What we really want, is an index. That way, we can compare characters from both strings, that are at the same position in the string. The first character of each string, then the second character of each, then the third, etc.
Does this make more sense?
Does this make more sense?
>>> first = 'socks' >>> second= 'laces' >>> for ndx in range(len(first)): ... left = first[ndx] ... right = second[ndx] ... print("Index we're comparing: {0}".format(ndx)) ... print("Character of first string at that index: {0}".format(left)) ... print("Character of second string at that index: {0}".format(right)) ... print("Are they the same? {0}".format(left == right)) ... print(" -- ") ... Index we're comparing: 0 Character of first string at that index: s Character of second string at that index: l Are they the same? False -- Index we're comparing: 1 Character of first string at that index: o Character of second string at that index: a Are they the same? False -- Index we're comparing: 2 Character of first string at that index: c Character of second string at that index: c Are they the same? True -- Index we're comparing: 3 Character of first string at that index: k Character of second string at that index: e Are they the same? False -- Index we're comparing: 4 Character of first string at that index: s Character of second string at that index: s Are they the same? True --