Debugging
def is_reverse(word1, word2):
if len(word1) != len(word2):
return False
i = 0
j = len(word2)
while j > 0:
if word1[i] != word2[j]:
return False
i = i+1
j = j-1
return True>>> is_reverse('pots', 'stop')
File "reverse.py", line 15,
in is_reverse if word1[i] != word2[j]:
IndexError: string index out of range
is_reverse.List
Do not write code for list in the same way as for strings
Pick an idiom and stick with it.
Make copies to avoid aliasing.
Last updated