在python中同时出现两个'for'循环

时间:2013-04-21 20:10:55

标签: python list

说我正在迭代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
"""

我怎么能这样做?

1 个答案:

答案 0 :(得分:4)

for i, j in zip(range(linecount - 1, -1, -1), range(linecount, -1, -1)):
    print i, j