I am trying to reverse the index given by enumerate
whilst retaining the original order of the list being enumerated.
Assume I have the following:
We can use enumerate with len:
$ cat enumerate.py
arr = ['stone', 'cold', 'steve', 'austin']
for i, val in enumerate(arr):
print ("enu {} val {}".format(i, val))
for i, val in enumerate(arr):
print ("enu {} val {}".format(len(arr) - i - 1, val))
$ python enumerate.py
enu 0 val stone
enu 1 val cold
enu 2 val steve
enu 3 val austin
enu 3 val stone
enu 2 val cold
enu 1 val steve
enu 0 val austin
$