如果是一個(gè)list, 最快的解決方案是:
list.reverse()
try:
for x in list:
“do something with x”
finally:
list.reverse()
如果不是list, 最通用但是稍慢的解決方案是:
for i in range(len(sequence)-1, -1, -1):
x = sequence[i]
<do something with x>
如果是一個(gè)list, 最快的解決方案是:
list.reverse()
try:
for x in list:
“do something with x”
finally:
list.reverse()
如果不是list, 最通用但是稍慢的解決方案是:
for i in range(len(sequence)-1, -1, -1):
x = sequence[i]
<do something with x>