iterating in reverse
Jonathan P.
jbperez808 at yahoo.com
Mon Jan 20 20:07:34 EST 2003
Chad Netzer <cnetzer at mail.arc.nasa.gov> wrote in message news:<mailman.1042798054.23362.python-list at python.org>...
> ~~~~~~~~~~~~~
> seq = "the quick brown fox jumped over the lazy dog"
> for i in xrange( len( seq ) ):
> forward_iter = seq[i]
> backward_iter = seq[-(i + 1)]
> pass # do whatever you need
> ~~~~~~~~~~~~~
>
> In this case, you don't copy or generate any new lists at all, so it
> should be quite quick.
Chad, I think this is the best solution so far.
Clean and fast and _obvious_. So much so that I'd
like to kick myself for not coming up with that
sooner. Sigh...
More information about the Python-list
mailing list