[x for y in z for x in zz if y in x]
Then you begin to wonder how great they really are.
[x for y in z for x in zz if y in x]
Then you begin to wonder how great they really are.
for y in z:
for x in zz:
if y in x:
yield x
It’s extremely easy to sight read. If the lines become long, just split them up and it’s even more obvious. [x
for y in z
for x in zz
if y in x]
There’s nothing tricky about multiple loops and conditions in comprehensions in most languages that support them. Just go left to right and it mirrors outer to inner loops/conditionals.{x : y ∈ z, x ∈ zz | y ∈ x}
If you've read enough statistics/ML papers, this becomes second nature.
As someone who breathes that style of notation, there is excellent support in vim and emacs for custom display for readability. Conceal syntax in vim¹(builtin for rust/help/$few_others and external such as vim-cute-python²), and pretty-mode³ in emacs. I'm sure similar things exist in other editors too, but I don't use those ;)
You don't get the exact representation in your example with the things I've mentioned, but if you're used to a more "mathy"-style they really are quite nice. YM[and taste]MV.
1. http://vimdoc.sourceforge.net/htmldoc/syntax.html#conceal
2. https://github.com/ehamberg/vim-cute-python (moresymbols branch for er… more symbols)