天天看点

python 列表解析(list comprehension)

[email protected]:~/Workspace$ ipython3

Python 3.5.2 (default, Nov 23 2017, 16:37:01)

Type ‘copyright’, ‘credits’ or ‘license’ for more information

IPython 6.5.0 – An enhanced Interactive Python. Type ‘?’ for help.

In [1]: a=[(a,b,c) for a in range(1,4) for b in range(5,7) for c in range(8, 10)]

In [2]: a

Out[2]:

[(1, 5, 8),

(1, 5, 9),

(1, 6, 8),

(1, 6, 9),

(2, 5, 8),

(2, 5, 9),

(2, 6, 8),

(2, 6, 9),

(3, 5, 8),

(3, 5, 9),

(3, 6, 8),

(3, 6, 9)]

In [3]:

继续阅读