List Comprehensions Enhancement
Greg Ewing
greg.ewing at compaq.com
Mon Sep 13 21:34:37 EDT 1999
William Tanksley wrote:
> On 13 Sep 1999 13:32:47 GMT, Hannah Schroeter wrote:>
> >The syntax looks a bit verbose, compared to e.g. Haskell's
>
> I actually liked the verbosity a lot.
My goal wasn't to make the syntax as compact (some might
say cryptic) as possible, but to import the idea and
make it blend in with the rest of the language.
> >Also, I think there should be a clear separator
>
> I agree -- my initial reaction was to put 'and' as the seperator.
There are problems with both of those. Using "," would
mean the expression couldn't be a tuple constructor without
using parentheses, which would be a potentially confusing
difference from the for statement. And I'm not sure what
the parser would make of "x and for" given that "x and y"
is a legal expression.
Semicolons could perhaps be used, although that seems
somehow un-pythonic to me.
Another possibility is to turn the whole thing around
and write
[for i in nums: for s in strs: (i, s)]
but that loses the declarative flavour of having the
element expression up front.
> On a scale of one to ten I'd give it a tim.
Hey, wow! And I haven't even gotten onto case statements
with pattern matching yet...
Greg
More information about the Python-list
mailing list