📜  python list comprehension double for - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:33.675000             🧑  作者: Mango

代码示例2
>>> l = [(x,y) for x in range(0,3) for y in range(5, 8)]
>>> l
[(0, 5), (0, 6), (0, 7), (1, 5), (1, 6), (1, 7), (2, 5), (2, 6), (2, 7)]

# they can also be "chained"
>>> l = [(x,y) for x in range(0,4) for y in range(0, x)]
>>> l
[(1, 0), (2, 0), (2, 1), (3, 0), (3, 1), (3, 2)]