3 ms·
You can think of the choice ( | ) as a generator function. X generates 1 then 2. Y generates 7 then 8. For x in [1,2]: For y in [7,8]: yield (x, y)
by jbritton 4y ago
You can think of the choice ( | ) as a generator function.
X generates 1 then 2.
Y generates 7 then 8.
For x in [1,2]:
For y in [7,8]:
yield (x, y)
- deleted 4y ago[deleted]
- psyklic 4y agoYou could also write the example as a list comprehension, which essentially mimics set-builder notation in math, i.e. "The set of all pairs such that ..." [(x, y) for x in [1, 2] for y in [7, 8]] // Python (list comprehension) {(x, y) | x \in {1, 2}, y \in {7, 8}} // math (set-builder notation)
- davidw 4y agoSee, the Python code has some hints as to what's going on. If you know that x is a variable, 'for x in' spells it out to some degree. Maybe you don't nail the exact functionality just from looking, but it feels more accessible.