[Tutor] implementing rot 13 problems

Danny Yoo dyoo at hashcollision.org
Tue Mar 12 07:20:27 CET 2013


The use of index() here to find the target place where the translation
is going to occur is very fragile.

Consider: we conceptually already should know where in the list we
want the target to be, since we're walking across the characters in
the list.  We know that we're looking first at ls[0], transforming it,
then ls[2], then ls[3], then...

The fact that we're using index() here, to try to recompute that
target position, is doing "extra" work: we're searching for something
that we should have already known.  And it turns out that not only is
it superfluous, but it's broken: there may be several places in the
list that qualify, not just the one that you're considering.


More information about the Tutor mailing list