I have the following code:
def hasPalin(string):
begin = 0
end = len(string)-1
result = ""
while(begin < len(string)/2):
if (string[begin] == string[end]):
result += string[begin]
else:
break
begin += 1
end -= 1
return result
Would it be possible to turn this while into a for ? That is, iterate over 2 variables, one being an increment, and another a decrease.
I did not test, but I'm pretty sure it's possible to do this in java, where I increment one variable, while decrementing another.