List Comprehensions Enhancement
William Tanksley
wtanksle at dolphin.openprojects.net
Tue Sep 14 21:12:47 EDT 1999
On Tue, 14 Sep 1999 13:34:37 +1200, Greg Ewing wrote:
>William Tanksley wrote:
>> On 13 Sep 1999 13:32:47 GMT, Hannah Schroeter wrote:>
>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.
I liked it.
>> >Also, I think there should be a clear separator
[he suggested a comma]
>> 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.
I hear you here -- but I tried to write a couple of comprehensions, and I
found that I was putting parenthesis in when needed. It's kind of
automatic after you've been working with Python for any amount of time.
>And I'm not sure what
>the parser would make of "x and for" given that "x and y"
>is a legal expression.
It's parsable, but given that it would require modifications to the parser
I have to retract my suggestion.
>Semicolons could perhaps be used, although that seems
>somehow un-pythonic to me.
I don't like it either. Commas have the advantage of looking like they're
talking about sequences, which in this case they indeed are.
>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.
Agreed. It also looks a little too much like a normal Python statement,
which it's not really.
>> 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...
Hey, Greg! Make us a 'while' statement which reads lines out of a file.
And why doesn't Python have a $_ variable?
:-)
>Greg
--
-William "Billy" Tanksley
More information about the Python-list
mailing list