Reputation: 5082
I am trying to build a range with an upper bound bigger than limit of integer in Python. I was looking for something like the following:
import sys
start = 100;
step = 100;
limit = sys.maxint + 1;
result = xrange(start, limit, step);
However, xrange
parameters are limited to the integer. According to Python Standard Library, I have to use itertools
module: islice(count(start, step), (stop-start+step-1)//step)
, but islice
seems to have the same integer limitations for the parameters.
Is there any other way to build the list with upper limit represented by long integer?
Upvotes: 0
Views: 1399
Reputation: 101565
xrange
is trivial to roll out on your own, so you can do just that:
def xlongrange(start, limit, step):
n = start
while n < limit:
yield n
n += step
Upvotes: 9