3 ms·
Whoever designed the comprehension syntax for Python was perhaps enamored of the "such that" math notation { expr-with-vars | constraint-predicates }. https://
by kazinator 9y ago
Whoever designed the comprehension syntax for Python was perhaps enamored of the "such that" math notation { expr-with-vars | constraint-predicates }.
https://en.wikipedia.org/wiki/Set-builder_notation#Sets_defined_by_a_predicate https://en.wikipedia.org/wiki/Set-builder_notation#Sets_defi...
- actsasbuffoon 9y agoThat's because Python's list comprehensions were derived from Haskell's implementation: https://wiki.python.org/moin/PythonVsHaskell#List_Comprehension_Syntax https://wiki.python.org/moin/PythonVsHaskell#List_Comprehens...:
- lmm 9y agoAs per https://wiki.haskell.org/List_comprehension https://wiki.haskell.org/List_comprehension , many Haskell users prefer to use do syntax (indeed I wasn't aware that the list comprehension syntax existed).
- actsasbuffoon 9y agoAgreed, I never use list comprehensions in Haskell. I feel like they're almost always harder to read.
- dmitriid 9y agoI wish they'd leave the math notation as is. Haskell's and Erlang's notations which keep it (maybe with slight modifications) are so much nicer and readable. Erlang [1]: [X || X <- [1,2,a,3,4,b,5,6], X > 3]. Pythagorean triplets [ {A,B,C} || A <- lists:seq(1,N), B <- lists:seq(1,N), C <- lists:seq(1,N), A+B+C =< N, A*A+B*B == C*C ]. [1] http://erlang.org/doc/programming_examples/list_comprehensions.html http://erlang.org/doc/programming_examples/list_comprehensio...