]> granicus.if.org Git - python/commitdiff
Add a new looping idiom
authorRaymond Hettinger <python@rcn.com>
Fri, 7 Nov 2003 01:30:58 +0000 (01:30 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 7 Nov 2003 01:30:58 +0000 (01:30 +0000)
Doc/tut/tut.tex

index e6017b07b2552b6d916bf0eb1360b58f6fe84760..508a7aef0fc8ae46e4a5e720d20e5969fcc4677c 100644 (file)
@@ -2162,6 +2162,21 @@ What is your quest?  It is the holy grail.
 What is your favorite color?  It is blue.
 \end{verbatim}
 
+To loop over a sequence in reverse, first specify the sequence
+in a forward direction and then call the \function{reversed()}
+function.
+
+\begin{verbatim}
+>>> for i in reversed(xrange(1,10,2)):
+...     print i
+...
+9
+7
+5
+3
+1
+\end{verbatim}
+
 
 \section{More on Conditions \label{conditions}}