count approach is called
naive in that it is akin to a first crack at the solution. It follows simple logic and reasoning and a learner might come up with that solution on their own, given a little thought about the problem.
Of course there are other solutions, such as the one you came up with (which is anything but naive). If we did not know about the
.index() method we would never arrive at this answer. Just like most learners at this stage will not know many
str methods, including
I would suggest that efficiency is the last thing we would need to consider at this point on the learning curve. Rather find all the myriad ways of solving this with the use of an algorithm (a plan of attack) that can be expressed in code.
It’s not clever or crafty solutions that are important, here. All working solutions are equally as good for our purposes. Put terms like ‘efficiency’ out of your mind for the time being and wait until you get into the sorts of problems that demand it or they take too long to run, and or use up too mahy resouces.
First we walk, then we run. Right now it is all about walking.