6. Looping backward
The key here is to avoid the awkward -1 values and nested functions (look at how many parenthesis pairs are involved). Use reverse to make your code more elegant.
6.1. Don’t do this
1names = ['john', 'jane', 'jeremy', 'janice', 'joyce', 'jonathan']
2
3for i in range(len(names) - 1, -1, -1):
4 print(names[i])
6.2. Do this
1names = ['john', 'jane', 'jeremy', 'janice', 'joyce', 'jonathan']
2
3for name in reversed(names):
4 print(name)