Posted in 面试题 onFebruary 04, 2012
如果是一个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]
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]
如何反序的迭代一个序列?how do I iterate over a sequence in reverse order
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@