rows = range(1,4)
cols = range(1,3)
cells = [(row, col) for row in rows for col in cols]
print(cells)
cells = [(row, col) for row in rows if row !=2 for col in cols if col !=1]
print(cells)
輸出:
[(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2)]
[(1, 2), (3, 2)]
參考資料:《Python語言及其應用》盧布諾維克 著