12

This is a simple question. I have

range(1, 11)[::-1]

which gives me

[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

Is there a 'cleaner' way to generate the above list? With a single function perhaps?

AsheKetchum
  • 1,098
  • 3
  • 14
  • 29

3 Answers3

22

You can use that range(10, 0, -1)

Moi Syme
  • 466
  • 2
  • 8
4

Using numpy you could do

import numpy as np
np.arange(10, 0, -1)
pingul
  • 3,351
  • 3
  • 25
  • 43
1

I don't know if it's cleaner but you could also use:

reversed(range(1, 11))
Giannis Spiliopoulos
  • 2,628
  • 18
  • 27