Question about the tasks and methods of solution


To solve the tasks I use ready-made methods for working with strings. For example to solve the task, I used an existing method for working with strings. And the code took only 3 lines
Am I doing the right thing, or need to manually write the code to avoid the use of existing methods. Just for the future I would like to know.
Sorry for the hideous English.


For practice, write out procedural code to start. Be able to reason out the steps involved in an algorithm to perform the task at hand. Then refactor. In most cases your refactored code should also pass, but this is not always so. The SCT may be looking for specific code patterns in which case following the instructions closely is the way to do the exercise.

Take for example the digit_sum problem. Can you write an algorithm that goes through all the steps? It will take a few lines of code. But then it can be refactored to one or two lines using built-ins.

@ionatan posted one such example in another topic (same category). I believe it went something like this:

sum(map(int, str(n)))

Not much practice got in that, though. I wouldn't give up on the procedural code, just yet. They have a singular advantage of being readable.

When the lesson allows it, I write all my refactored code in the lesson, along with the first procedural draft. Then it is simpler to review the progression.