[Python-Dev] comprehension abbreviation (was: Adding any() and
all())
Eric Nieuwland
eric.nieuwland at xs4all.nl
Tue Mar 15 22:46:36 CET 2005
Martin v. Löwis wrote:
> That's not the full syntax. The full syntax is
>
> [ <test> for <exprlist> in <testlist> <list-iter-opt> ]
>
> where
>
> <test> can be an arbitrary expression: and, or, lambda, +, -, ...
> <exprlist> can be a list of expression, except for boolean and
> relational expressions (but I think this is further constrained
> semantically)
> <testlist> list a list of tests
> <list-iter-opt> is optional, and can be another for or if block
Aren't these names a bit mixed up w.r.t. what's in that position? As
far as I know
<test> is not a test but a function as it produces any value not just
True/False
<exprlst> is a list of names, not arbitrary expressions
<testlist> is anything which will produce an iterator
Or so I've understood so far.
> So a more complex example is
>
> [ lambda a: a[x]+y*z for x,y in A for z in B if x > z]
I'm schocked ;-)
--eric
More information about the Python-Dev
mailing list