range()
and xrange()
work for 10-digit-numbers. But how about 13-digit-numbers? I didn't find anything in the forum.
You could try this. Same semantics as range:
import operator
def lrange(num1, num2 = None, step = 1):
op = operator.__lt__
if num2 is None:
num1, num2 = 0, num1
if num2 < num1:
if step > 0:
num1 = num2
op = operator.__gt__
elif step < 0:
num1 = num2
while op(num1, num2):
yield num1
num1 += step
>>> list(lrange(138264128374162347812634134, 138264128374162347812634140))
[138264128374162347812634134L, 138264128374162347812634135L, 138264128374162347812634136L, 138264128374162347812634137L, 138264128374162347812634138L, 138264128374162347812634139L]
Another solution would be using itertools.islice
, as suggested inxrange
's documentation
No problems with creating the range, as long as you don't want 10**13 elements, e.g.
range(10**14,10**15,10**14)
gives
[100000000000000, 200000000000000, 300000000000000, 400000000000000, 500000000000000, 600000000000000, 700000000000000, 800000000000000, 900000000000000]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With