From the course: Python Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Encoding ASCII art

Solution: Encoding ASCII art - Python Tutorial

From the course: Python Essential Training

Solution: Encoding ASCII art

- [Instructor] Hopefully this challenge put a smile on your face and on your screens. The encodeString function here looks like a lot of code, unless maybe you did it in a more efficient way or at least a shorter way than I did. It's really not that tricky. Just a little tedious to keep track of everything. And this is where having well-named variables really comes in handy to make it clear what's going on. So here we have the stringVal that gets passed in and we want to ultimately loop through that. Along the way, we're going to keep track of a few things. So the first is our encodedList. This is what ultimately gets returned from the function. Then we have prevChar. This is so we know when the string has changed. If the current character doesn't match what the prevChar is, we know that we need to add something to the encodedList. And finally, we'll keep track of the count. This starts at zero and it just keeps track of how many characters we've gone through without seeing any change…

Contents