xrange

xrange versus itertools.count Python 2.7

穿精又带淫゛_ 提交于 2020-01-04 02:16:30
问题 I want to run a range from a start to an end value. It works fine on low numbers but when it gets too large it causes an overflow error as int too large to convert to C Long. I am using Python 2.7.3. I read here OverflowError Python int too large to convert to C long on using the itertools.count() method except that method works differently to the xrange method by stepping as opposed to declaring an end range value. Can the itertools.count() be set up to work like xrange() ? print "Range

range and xrange for 13-digit numbers in Python?

微笑、不失礼 提交于 2019-12-17 16:35:39
问题 range() and xrange() work for 10-digit-numbers. But how about 13-digit-numbers? I didn't find anything in the forum. 回答1: 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))

NameError: global name 'xrange' is not defined in Python 3

梦想与她 提交于 2019-12-17 05:33:29
问题 I am getting an error when running a python program: Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 110, in <module> File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 27, in __init__ File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\class\inventory.py", line 17, in __init__ builtins.NameError: global name 'xrange' is not defined The game is from here. What causes this error?

`xrange(2**100)` -> OverflowError: long int too large to convert to int

北城以北 提交于 2019-12-17 03:20:11
问题 xrange function doesn't work for large integers: >>> N = 10**100 >>> xrange(N) Traceback (most recent call last): ... OverflowError: long int too large to convert to int >>> xrange(N, N+10) Traceback (most recent call last): ... OverflowError: long int too large to convert to int Python 3.x: >>> N = 10**100 >>> r = range(N) >>> r = range(N, N+10) >>> len(r) 10 Is there a backport of py3k builtin range() function for Python 2.x? Edit I'm looking for a complete implementation of "lazy" range()

Name 'xrange' is not defined in Python 3 [duplicate]

泪湿孤枕 提交于 2019-12-09 04:42:50
问题 This question already has answers here : NameError: global name 'xrange' is not defined in Python 3 (6 answers) Closed 4 years ago . I try to execute following code but can't with mistake: name 'xrange' is not defined pages = ( requests.get( build_group_request({ "offset": WINDOW_SIZE * i, "count": WINDOW_SIZE, "fields": "sex,interests,bdate" }) ).json()['response']['items'] for i in xrange(int(float(COUNT) / 100 + 1)) ) 回答1: You're probably using Python3, where xrange has become range . 来源:

Number Sequence in MySQL

拥有回忆 提交于 2019-12-07 22:58:21
问题 In Python if I wanted a sequence from 0 - 9 (inclusive) I would use xrange(0,10) . Is there a way I can do this in MySQL? 回答1: Since there is no such thing as xrange, one could use a separate table stored with integer (as previously answered), or just make a stored procedure to do the job: DROP PROCEDURE IF EXISTS xrange; DELIMITER // CREATE PROCEDURE xrange(x INT, y INT) BEGIN DECLARE i INT DEFAULT x; CREATE TEMPORARY TABLE xrange_tmp (c1 INT); WHILE i < y DO INSERT INTO xrange_tmp VALUES (i

Number Sequence in MySQL

我只是一个虾纸丫 提交于 2019-12-06 08:09:24
In Python if I wanted a sequence from 0 - 9 (inclusive) I would use xrange(0,10) . Is there a way I can do this in MySQL? Since there is no such thing as xrange, one could use a separate table stored with integer (as previously answered), or just make a stored procedure to do the job: DROP PROCEDURE IF EXISTS xrange; DELIMITER // CREATE PROCEDURE xrange(x INT, y INT) BEGIN DECLARE i INT DEFAULT x; CREATE TEMPORARY TABLE xrange_tmp (c1 INT); WHILE i < y DO INSERT INTO xrange_tmp VALUES (i); SET i = i + 1; END WHILE; END; // Usage: CALL xrange(-2,10); SELECT c1 FROM xrange_tmp; DROP TABLE xrange

changing default x range in histogram matplotlib

不羁的心 提交于 2019-12-03 16:16:26
问题 I would like to change the default x range for the histogram plot. The range of the data is from 7 to 12. However, by default the histogram starts right at 7 and ends at 13. I want it to start at 6.5 and end at 12.5. However, the ticks should go from 7 to 12.How do I do it? import asciitable import numpy as np import matplotlib.pyplot as plt import matplotlib.mlab as mlab import pylab from pylab import xticks data = asciitable.read(file) hmag = data['col8'] visits = data['col14'] origin =

How is irange() any different from range() or xrange()?

我的梦境 提交于 2019-12-03 12:36:26
问题 I was going through Python Generators Wiki when I came across this RangeGenerator page which talks about irange() - This will let us iterator over large spans of numbers without resorting to xrange, which is a lazy list as opposed to a generator. I can't seem to understand the test suite and the implementation described on that page. I know that range() creates a list in the memory (from Python 2.7 point of view) and xrange() is a generator. How is irange() any different? 回答1: irange()

Is there an equivalent of Pythons range(12) in C#?

孤人 提交于 2019-12-03 11:27:43
问题 This crops up every now and then for me: I have some C# code badly wanting the range() function available in Python. I am aware of using for (int i = 0; i < 12; i++) { // add code here } But this brakes down in functional usages, as when I want to do a Linq Sum() instead of writing the above loop. Is there any builtin? I guess I could always just roll my own with a yield or such, but this would be so handy to just have . 回答1: You're looking for the Enumerable.Range method: var mySequence =