xrange

Reason why xrange is not inheritable in Python?

Reason why xrange is not inheritable in Python? Question: I was trying to inherit xrange (to implement membership testing with in, as well as iteration). But I got the following error message: TypeError: Error when calling the metaclass bases type ‘xrange’ is not an acceptable base type What’s special about xrange? Asked By: Frozen Flame …

Total answers: 1

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

NameError: global name 'xrange' is not defined in Python 3 Question: I am getting an error when running a python program: Traceback (most recent call last): File “C:Program Files (x86)Wing IDE 101 4.1srcdebugtserver_sandbox.py”, line 110, in <module> File “C:Program Files (x86)Wing IDE 101 4.1srcdebugtserver_sandbox.py”, line 27, in __init__ File “C:Program Files (x86)Wing IDE 101 4.1srcdebugtserverclassinventory.py”, …

Total answers: 6

Why is there no xrange function in Python3?

Why is there no xrange function in Python3? Question: Recently I started using Python3 and it’s lack of xrange hurts. Simple example: Python2: from time import time as t def count(): st = t() [x for x in xrange(10000000) if x%4 == 0] et = t() print et-st count() Python3: from time import time as …

Total answers: 6

changing default x range in histogram matplotlib

changing default x range in histogram matplotlib Question: 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. …

Total answers: 3

why is xrange able to go back to beginning in Python?

why is xrange able to go back to beginning in Python? Question: I’ve encountered this code from Most pythonic way of counting matching elements in something iterable r = xrange(1, 10) print sum(1 for v in r if v % 2 == 0) # 4 print sum(1 for v in r if v % 3 …

Total answers: 3

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

Is there an equivalent of Pythons range(12) in C#? Question: 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 …

Total answers: 5

Should you always favor xrange() over range()?

Should you always favor xrange() over range()? Question: Why or why not? Asked By: mbac32768 || Source Answers: xrange() is more efficient because instead of generating a list of objects, it just generates one object at a time. Instead of 100 integers, and all of their overhead, and the list to put them in, you …

Total answers: 12

What is the difference between range and xrange functions in Python 2.X?

What is the difference between range and xrange functions in Python 2.X? Question: Apparently xrange is faster but I have no idea why it’s faster (and no proof besides the anecdotal so far that it is faster) or what besides that is different about for i in range(0, 20): for i in xrange(0, 20): Asked …

Total answers: 28