2

假设我正在遍历 python 中的列表:

lines = [1, 2, 3, 4]

linecount = len(lines)

#I want to be able to do this:
for i, j in range(linecount - 1, -1, -1), range(linecount, -1, -1):
    print i, j

"""
This would print out
3 4
2 3
1 2
0 1
0 0
"""

我怎么能这样做呢?

4

1 回答 1

5
for i, j in zip(range(linecount - 1, -1, -1), range(linecount, -1, -1)):
    print i, j
于 2013-04-21T20:13:12.303 回答