Terry J. Reedy <tjre...@udel.edu> added the comment: 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. ---------- nosy: +terry.reedy _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue12003> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com