Python面试真题-how do I iterate over a sequence in reverse order?
【Python面试真题】-how do I iterate over a sequence in reverse order?
for x in reversed(sequence):
... # do something with x..
如果不是list, 最通用但是稍慢的解决方案是:
for i in range(len(sequence)-1, -1, -1):
x = sequence[i]
<do something with x>