标签:
#1
for index, val in enumerate(reversed(list)):
print len(list) - index - 1, val
#2
def reverse_enum(L):
for index in reversed(xrange(len(L))):
yield index, L[index]
L = [‘foo‘, ‘bar‘, ‘bas‘]
for index, item in reverse_enum(L):
print index, item
#3
L = [‘foo‘, ‘bar‘, ‘bas‘]
for index in reversed(range(len(L))):
print index, L[index]
Python: How to iterate list in reverse order
标签:
原文地址:http://www.cnblogs.com/lynnge/p/5100458.html