我试图在Python中构建一个上限大于整数限制的范围.我一直在寻找以下内容:
import sys
start = 100;
step = 100;
limit = sys.maxint + 1;
result = xrange(start, limit, step);
Run Code Online (Sandbox Code Playgroud)
但是,xrange参数仅限于整数.根据Python标准库,我必须使用itertoolsmodule : islice(count(start, step), (stop-start+step-1)//step),但islice似乎对参数有相同的整数限制.
有没有其他方法来构建具有由长整数表示的上限的列表?
xrange 你自己推出是微不足道的,所以你可以做到这一点:
def xlongrange(start, limit, step):
n = start
while n < limit:
yield n
n += step
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1382 次 |
| 最近记录: |