Creating a Reverse Sequence of Numbers in Python

Let’s say you want to create a sequence of numbers in reverse order (for example, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1). I tried to do this with the range function, but I couldn’t find a way to do it. But Python has a built-in function called reversed that allows you to do this. An easy way to implement this is loop over it as below:

print [x for x in reversed(range(1, 11, 1))]

One Response to “Creating a Reverse Sequence of Numbers in Python”

  1. or with range with a negative increment:
    >>>range(10,0,-1)

Leave a Reply