Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)



You 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)


See, 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: