【发布时间】:2008-12-01 02:44:03
【问题描述】:
基本上,我想在两个迭代器的“笛卡尔积”上构建一个列表理解。想想下面Haskell code:
[(i,j) | i <- [1,2], j <- [1..4]]
产生
[(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(2,4)]
能否以简洁的方式在 Python 中获得类似的行为?
【问题讨论】:
标签: python iterator list-comprehension