11/19/2023 0 Comments Python splice string and reverse![]() ![]() In the context of recursion, you've reached the base case. This is when you've put "e", "d", "o", and "c" in the correct positions, and you don't have to do it any longer.You're now left with reversing "" – an empty string.Do it a couple more times – pull out "d" first, and then "e".Now that "c" and "o" have been taken care of, you're left with the problem of reversing the substring "de".And push it to the last slot available on the right. You can do the very same task of pulling out the first letter yet again, now "o".And the problem has reduced to reversing this substring "ode" You're now left with the string "ode".So pull out the first letter – "c" here – and push it to the very end.The first letter in the original string will be the last letter in the reversed string, yes? Let's forget recursion for a while, and start with what you know. And to do this, consider the string "code". Let's now discuss the motivation behind reversing strings intuitively. And the function doesn’t have to call itself any longer – this is called the base case. And this goes on until there’s no work left to do.Each recursive function call does the same small amount of work. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |