reversed(xrange(1, len(x))) is inefficient, xrange(len(x) - 1, 0, -1) gives exactly the same sequence but avoid reversed(). See attached patch. Don't expect amazing speedup.
-1 on this patch. Reversed has a very low overhead. Readability if more important. The current code is self-evidently correct but the patched code is less obviously so.
FWIW, the inefficiency is only in the loop setup, the time to call reversed() and __reversed__(). The inner loop runs at the same speed because xrange provides a __reversed__ iterator. Please do not go through the standard library making these minor tweaks without making sure there is a significant measured speed-up and do consider the readability issue.
History
Date
User
Action
Args
2022-04-11 14:56:48
admin
set
github: 50236
2009-05-11 07:44:24
rhettinger
set
status: open -> closedresolution: rejectedmessages: +