#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]
时间: 2024-10-05 14:34:13