[issue7721] Code in xrange documentation does not work

2010-04-05 Thread Georg Brandl
Georg Brandl added the comment: Thanks, fixed in release26-maint r79796. -- resolution: -> fixed status: open -> closed ___ Python tracker ___ __

[issue7721] Code in xrange documentation does not work

2010-02-20 Thread Martin Manns
Martin Manns added the comment: So could we replace "If a larger range is needed, an alternate version can be crafted using the itertools module: islice(count(start, step), (stop-start+step-1)//step)." by "If a larger range is needed, an alternate version can be crafted using the itertools

[issue7721] Code in xrange documentation does not work

2010-01-17 Thread Mark Dickinson
Changes by Mark Dickinson : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pyt

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Martin Manns
Martin Manns added the comment: Great solution! Thank you -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: h

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Florent Xicluna
Florent Xicluna added the comment: If you need also negative steps: from itertools import count, takewhile def irange(start, stop, step): if step < 0: cond = lambda x: x > stop else: cond = lambda x: x < stop return takewhile(cond, (start + i * step for i in count())

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Florent Xicluna
Florent Xicluna added the comment: You will prefer this one. It is as fast as the 2.7 version. The restrictions are described in the itertools documentation. from itertools import count, takewhile irange = lambda start, stop, step: takewhile(lambda x: x>> list(irange(-2**65,2**65,2**61)) [-368

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Florent Xicluna
Florent Xicluna added the comment: You will prefer this one. It is as fast as the 2.7 version. from itertools import count, takewhile irange = lambda start, stop, step: takewhile(lambda x: x>> list(irange(-2**65,2**65,2**61)) [-36893488147419103232L, -34587645138205409280L, ... -- ___

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Martin Manns
Martin Manns added the comment: The new snippet works better. >>> list(irange(-12, 20, 4)) [-12, -8, -4, 0, 4, 8, 12, 16] However, it does not like large or negative slices: >>> list(irange(-2**65,2**65,2**61)) Traceback (most recent call last): File "", line 1, in File "", line 1, in O

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Florent Xicluna
Florent Xicluna added the comment: Right. Insufficient test. This snippet looks better, if we provide a replacement for 2.6. >>> irange = lambda start, stop, step: islice(count(start), 0, stop-start, step) -- ___ Python tracker

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Martin Manns
Martin Manns added the comment: The new snippet does not work for me: >>> list(irange(-12, 20, 4)) [-12, -8, -4, 0, 4] I have attached code that seems to work. It is more than a snipped though. -- Added file: http://bugs.python.org/file15922/irange.py

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Florent Xicluna
Florent Xicluna added the comment: Confirmed. The snippet works for 3.1 and 2.7a2. from itertools import count, islice irange = lambda start, stop, step: islice(count(start, step), (stop-start+step-1)//step) The documentation needs update for 2.6 only. This kind of snippet seems backward co

[issue7721] Code in xrange documentation does not work

2010-01-16 Thread Martin Manns
New submission from Martin Manns : In the Python 2.6.4 documentation "2. Built-in Functions" at http://docs.python.org/library/functions.html, the section about the xrange function (paragraph "CPython implementation detail") contains the following code: islice(count(start, step), (stop-start+st