1
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
It would be possible to transform this while in a for? That is, iterate over 2 variables, one being an increment, and the other a decrement.
I haven’t tested it, but I’m pretty sure it’s possible to do this in java, where I increment one variable while decreasing another.
Could you say what the purpose of this function is?
– Sidon
@Sidon It checks whether the beginning of a string is equal to the end, like a palindrome sub, being input: abcqwertbca, the output would be: abc. But my biggest doubt is whether it is possible to make one such feature.
– Vinicius Macelai