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>