Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dmitriy Romanov |
I am trying to get better with recursion, and one excercise I came upon was to revert a string. At first I was trying to solve this by any means possible, and my first code had ~50 lines. Step by step, improving it , and reading all the Google, I ended up with this:
func three(input):
if input == "":
return input
else:
return input[-1] + three(input.resize(len(input) - 1))
The only problem is - there’s no resize function with strings. Alternatively, I’ve seen solutions doing “return everything but the last symbol”.
Here’s the best explanation: Python reversing a string using recursion - Stack Overflow
This is guy’s code:
def backward(text):
if text == "":
return text
else:
return text[-1] + backward(text[:-1])
(Resembles something, huh?))
But. There’s no “call everything but the last symbol” function/syntaxis in GDSript.
Or is there? Please, help.