Search code examples
pythonpython-3.xrange

Get specific form of range in Python 3


When getting range(1,100) I get:

[ 1, 2, 3, 4, 5 ... 99 ]

I need something like zip of this range:

[ 50, 49, 51, 48, 52, 47, 53 ... 99 ]

How to get it?


Background: It is all about Bitcoin puzzle 66.

First I made prediction with linear regression for past known private keys till puzzle 65 including. I put puzzle 66 and two following as the prediction I want to get. I got three integer numbers.

Now I don't want to search from number-1M to number+1M because I might be closer to the real private key with the original number, so I need to search from the middle. And that's what the answer is needed for.


Solution

  • Alternatively, you can assign to list slices:

    out = [0] * 99
    out[::2], out[1::2] = range(50, 100), range(49, 0, -1)
    
    print(out)
    

    This prints:

    [50, 49, 51, 48, 52, ... 2, 98, 1, 99]