In [1]: [x**2 for x in range(5) if x < 2] Out[1]: [0, 1]
In [2]: [x**2 for x in range(5)] Out[2]: [0, 1, 4, 9, 16]
In [3]: [(x, x**2) for x in (1, 2, 3, 4, 5, 6) if x % 3] Out[3]: [(1, 1), (2, 4), (4, 16), (5, 25)]
In [4]: [(x, y) for x in range(5) if not x % 3 for y in range(5) if not y % 2] Out[4]: [(0, 0), (0, 2), (0, 4), (3, 0), (3, 2), (3, 4)]
In [7]: [sum([x, y]) for x in range(5) for y in range(2)] Out[7]: [0, 1, 1, 2, 2, 3, 3, 4, 4, 5]
In [8]: [sum([x, y]) for (x, y) in zip([1, 2, 3, 4], [2, 3, 4, 5])] Out[8]: [3, 5, 7, 9]
|