python – Print a word, one character per line, backwards

Looking at the two implementations side by side, ignoring the goal of the exercise and alternative implementations, I’d say the second example is better:

  • It uses one fewer variables.
  • It does a simple index lookup rather than a slice.
  • The implementation is easier to follow.

For simple problems like this it’s often useful to think of the complexity of the solution as the number of “tokens”, or distinct language elements, necessary to write it down. For example, print(cont2) is four tokens: print, (, cont2 and ). By a quick read the first example has about twice as many tokens as the second.