List Comprehensions Enhancement
William Tanksley
wtanksle at dolphin.openprojects.net
Mon Sep 13 14:49:40 EDT 1999
On 13 Sep 1999 13:32:47 GMT, Hannah Schroeter wrote:
>Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:
>>print [3 * x for x in nums]
>>print [x for x in nums if x > 2]
>>print [(i, s) for i in nums for s in strs]
>>print [(i, s) for i in nums for s in [f for f in strs if "n" in f]]
>The syntax looks a bit verbose, compared to e.g. Haskell's list
>comprehension syntax which looks quite similar to the mathematical set
>comprehensions:
I actually liked the verbosity a lot. I thought it was extremely cool;
I'd like to see this in Python, although I suspect it won't make it (it's
a little too much like a functional language).
>Also, I think there should be a clear separator between the
>generators/predicates in your syntax too:
>print [(i,s) for i in nums, for s in strs]
>or similar.
I agree -- my initial reaction was to put 'and' as the seperator. Amazing
how great minds think alike :).
print [(i,s) for i in nums and for s in strs]
>Nice thing, though :-)
Oh, amazingly. Thanks, Greg. On a scale of one to ten I'd give it a tim.
>Regards, Hannah.
--
-William "Billy" Tanksley
More information about the Python-list
mailing list