In Python2.x, the simplest solution in terms of character count should be:
>>> a=range(20) >>> a[::-1] [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
Although I want to point out that when using xrange (), indexing will not work, because xrange () provides you with an xrange object instead of a list.
>>> a=xrange(20) >>> a[::-1] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sequence index must be integer, not 'slice'
After in Python3.x, range () does what xrange () does in Python2.x, but also has an improvement that accepts changing the indexing of an object.
>>> a = range(20) >>> a[::-1] range(19, -1, -1) >>> b=a[::-1] >>> for i in b: ... print (i) ... 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 >>>
difference between range () and xrange () obtained from source: http://pythoncentral.io/how-to-use-pythons-xrange-and-range/ author: Joey Payne