3 ms·
I get that to some degree, but that code doesn't look like something most people are exposed to, whereas 'x = 10' or something that says 'foreach' seems like it
by davidw 4y ago
I get that to some degree, but that code doesn't look like something most people are exposed to, whereas 'x = 10' or something that says 'foreach' seems like it'd make sense with a minimum of explanation to a lot of people.
x:=(1|2); y:=(7|8); (x,y)
Doesn't look like any math I'm familiar with.
- jbritton 4y agoYou 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.
- yazzku 4y agoCartesian product.