in Education by
What makes using range() to make the process of generating a quadrillion values in a instant of time, I am amazed by this can anyone answer this question? I also tried to run my own function but it didn't helped me: def my_crappy_range(N): o = 0 while o< N: yield o o += 1 return Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
The reason behind the speed is that in Python 3+ we're using mathematical reasoning about the bounds instead of a direct iteration. It just check all the objects between start and stop and stride value doesn't step over the numbers. For Ref. you can check the following code: >>> y, x = 10000000000000, range(10000000000001) >>> class MyInt(int): ... pass ... >>> y_ = MyInt(y) >>> y in x # calculates immediately :) True >>> y_ in x # iterates for ages.. :( ^\Quit (core dumped) Happy Learning.

Related questions

0 votes
    Is there a built-in that removes duplicates from a list in Python, whilst preserving order? I know that I can ... idiom if possible. Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    Currently I am working on this code: customer_telno = customer.find('div', 'customer_phone_number') customer_telno = ... this problem? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Is there a way to step between 0 and 1 by 0.1? I thought I could do it like the following, but it failed: ... , which I did not expect. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Please tell me what random.seed() does in Python. For example, why do the below trials do what they do ( ... randint(1, 10) 7 Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    Apparently xrange is faster but I have no idea why it's faster (and no proof besides the anecdotal so far that it ... xrange(0, 20): Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Here is a pure Python-specific design question: class MyClass(object): ... def get_my_attr(self): ... def ... you use and why? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I want to freeze the dos pop-up, I already tried raw-input as mentioned in my study material of Python 2.6 and ... (3**200) raw_input() Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Can someone tell me a python -m SimpleHTTPServer equivalent Python 3? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    This my my JSON: { "maps": [ { "id": "AT", "iscategorical": "0" }, { "id": "AT", "iscategorical": "0 ... the values, How can I do it? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I am confused about the usage of string.join(list) instead of list.join(string), for instance see this code: ... reason behind this? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I want to write a program which returns different values for different input,it can be easily done using switch ... some alternative? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    How can I convert a str from uppercase, or half uppercase to lowercase? E.x. "Decimeter" to "decimeter" Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    How can I get the number of elements of a list? Ex- items = [] items.append("one") items.append("two") items.append("three") Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I am a learner and just want to know the basic concept of super(). Here in the given code I want to know ... () ChildOne() ChildTwo() Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    In a list with range(1,16) and I am trying to divide this list in some fixed numbe n . Let's assume n=7 ... uneven, How can I do that? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
...