From the course: Python: Recursion

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

String length recursive algorithm

String length recursive algorithm - Python Tutorial

From the course: Python: Recursion

Start my 1-month free trial

String length recursive algorithm

- [instructor] The third and final challenge for this chapter. This is to use recursion to find the length of a string. Now we're going to do the iterative version first as before. If you want to try this for yourself, then pause the video now for iterative version and welcome back if you went away for the iterative version this is going to look like results = zero. This is a very, very common pattern. I call it the accumulator pattern. It's not a design pattern as such in the sense of some of the kind of more formal design patterns but it's very useful in terms of thinking about an algorithm where you have an empty, I call it an empty bucket. So here result is like an empty bucket and when it's an integer, it's zero. And then you iterate through some collection and you modify the empty bucket. You fill the bucket, and then at the end of the function you return it. So a code is the accumulator pattern. I'm not sure if…

Contents