Georg Brandl ge...@python.org added the comment:
Thanks, fixed in release26-maint r79796.
--
resolution: - fixed
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7721
___
Martin Manns mma...@gmx.net 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
Changes by Mark Dickinson dicki...@gmail.com:
--
nosy: +rhettinger
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7721
___
___
Python-bugs-list
New submission from Martin Manns mma...@gmx.net:
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),
Florent Xicluna la...@yahoo.fr 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
Martin Manns mma...@gmx.net 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
Florent Xicluna la...@yahoo.fr 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
Martin Manns mma...@gmx.net 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 stdin, line 1, in module
File
Florent Xicluna la...@yahoo.fr 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: xstop, (start+i*step
for i in count()))
list(irange(-2**65,2**65,2**61))
Florent Xicluna la...@yahoo.fr 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: xstop, (start+i*step
for i
Martin Manns mma...@gmx.net added the comment:
Great solution!
Thank you
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7721
___
___
11 matches
Mail list logo