[docs] BUG: Looping in reverse order

Valentin V. Bartenev vbartenev at gmail.com
Tue Aug 16 03:38:54 CEST 2011


Hello,

Section 5.6 of the Python 3 Tutorial: http://docs.python.org/py3k/tutorial/datastructures.html#looping-techniques
propose a too complicated way to loop over a sequence in reverse order.

The example teaches bad programming practice:
>>> for i in reversed(range(1, 10, 2)):
...     print(i)
...
9
7
5
3
1

it should be more simple:
>>> for i in range(9, 0, -2):
...     print(i)
... 
9
7
5
3
1

I figure out that the author just wanted to introduce "reversed" function,
but he choose an inappropriate use case.

wbr, Valentin V. Bartenev


More information about the docs mailing list