Terry Reedy wrote:
> "Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> | In py3k it expands to:
> |
> | def <anon>(outermost):
> | %0 = []
> | for x in outermost:
> | for y in seq2:
> | %0.append(x*y) # Special opcode, not a normal call
> | return %0
> | %n = <anon>(seq1)
>
> Why not pass both seq1 *and* seq2 to the function so both become locals?
> The difference of treatment is quite surprising.
The inner iterable expressions can't be evaluated early, as they need to
be re-evaluated for each pass around the outer loop (or loops). An
example where the iterable expression for the inner loop refers to the
iteration variable of the outer loop should make that clear:
.>>> [y for x in range(4) for y in range(x)]
[0, 0, 1, 0, 1, 2]
The advantage of the Py3k approach is that it eliminates the current
semantic differences between a list comprehension and list() with a
generator expression argument, while keeping most of the performance
benefits of the special syntax.
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com