ramesh.mimit ramesh.mimit - 1 month ago 12
Python Question

Print a list in reverse order with range()?

How can you produce the following list with

range()
in Python?

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

Answer

use reversed() function:

reversed(range(10))

It's much more meaningful.

Update:

If you want it to be a list (as btk pointed out):

list(reversed(range(10)))