This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients docs@python, eric.araujo, ezio.melotti, rhettinger, tenuki, terry.reedy
Date 2011-05-07.07:23:49
SpamBayes Score 7.1789605e-06
Marked as misclassified No
Message-id <1304753030.01.0.318221754684.issue12003@psf.upfronthosting.co.za>
In-reply-to
Content
I verified bug on winxp with 2.7
xrangef [5, 4, 3, 2, 1, 0]
py26 []
py27 [5, 4, 3, 2, 1, 0, -1, -2]
v1 [5, 4, 3, 2, 1, 0]
v2 [5, 4, 3, 2, 1, 0]
v3 [5, 4, 3, 2, 1, 0]
-----------------------
xrangef [5, 3, 1, -1, -3]
py26 []
py27 [5, 3, 1, -1, -3, -5]
v1 [5, 3, 1, -1, -3]
v2 [5, 3, 1, -1, -3]
v3 [5, 3, 1, -1, -3]

The problem is that -1 should instead be +1 for negative steps. The 2.6 version completely failed for negative steps because the comparison needs to be reversed. The doc example could add "for positive steps. For negative steps, use '+1' instead of '-1'". Or change expression to
islice(count(start, step), (stop-start+step-1+2*(step<0))//step)
(the addition is  +2*(step<0)).
Or change -1 to +(-1 if step>0 else 1). I tested both.
History
Date User Action Args
2011-05-07 07:23:50terry.reedysetrecipients: + terry.reedy, rhettinger, ezio.melotti, eric.araujo, tenuki, docs@python
2011-05-07 07:23:50terry.reedysetmessageid: <1304753030.01.0.318221754684.issue12003@psf.upfronthosting.co.za>
2011-05-07 07:23:49terry.reedylinkissue12003 messages
2011-05-07 07:23:49terry.reedycreate