相关疑难解决方法(0)

具有Itertools的等效嵌套循环结构

Python的succint语法通过其电池允许详细的代码行以可读的一行表示.请考虑以下示例

====================================================|
for a in range(3):                                  |
    for b in range(3):                              |
        for c in range(3):                          |
            print (a,b,c),                          |
-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -|
for e in product(range(3), repeat=3):               |
    print e,                                        |
====================================================|
for a in range(3):                                  |
    for b in range(a , 3):                          |
        for c in range(b , 3):                      |
            print (a,b,c),                          |
-  -  -  -  -  -  -  -  -  - …
Run Code Online (Sandbox Code Playgroud)

python foreach python-itertools python-2.7

12
推荐指数
2
解决办法
1610
查看次数

标签 统计

foreach ×1

python ×1

python-2.7 ×1

python-itertools ×1