[docs] BUG: Looping in reverse order

Sandro Tosi sandro.tosi at gmail.com
Thu Aug 18 14:48:52 CEST 2011


Hello Valentin,
thanks for your email.

On Tue, Aug 16, 2011 at 03:38, Valentin V. Bartenev <vbartenev at gmail.com> wrote:
> 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.

Indeed, it's just about presenting the reversed() function: in fact,
the next paragraph is about sorted().

Hence, I don't see anything wrong here, and the doc doesn't require an update.

Regards,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi


More information about the docs mailing list