As presented in the chapter:
def HasTwoAndLater(astr): |
for i in range(len(astr)-1): |
if astr[i]==astr[i+1]: |
break |
# now, out of the loop; astr[i] is the double letter |
# but "return" instead of break would be incorrect |
for j in range(i+2,len(astr)): |
if astr[j]==astr[i]: |
return True |
# in this second loop, early return is OK |
return False |
print HasTwoAndLater("too far") |
print HasTwoAndLater("see me") |