Message135407
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. |
|
Date |
User |
Action |
Args |
2011-05-07 07:23:50 | terry.reedy | set | recipients:
+ terry.reedy, rhettinger, ezio.melotti, eric.araujo, tenuki, docs@python |
2011-05-07 07:23:50 | terry.reedy | set | messageid: <1304753030.01.0.318221754684.issue12003@psf.upfronthosting.co.za> |
2011-05-07 07:23:49 | terry.reedy | link | issue12003 messages |
2011-05-07 07:23:49 | terry.reedy | create | |
|