by TuringTest · 3y ago · 0 comments
[(x, y) for x in [1, 3, 5] for y in [2, 7, 8] if x < y]
It's a single monolithic expression that builds the list. The choice syntax however represents each generator and each test as separate expressions, which may even be part of different functions. This seems to offer more flexibility. For example (I don't know the exact syntax):
x:=(1|2); y:=(7|8); x<y; result = (x,y)
Here result is bound to the same values as in the comprehensive list; but these values are yield one at a time, instead of being part of a structure that you traverse.
No comments yet.