Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

50, 49, 51, 48, 52, 47, 53

How to get it?

>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)

Prints:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading