A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-October/039284.html below:

[Python-Dev] listcomps vs. for loops

[Python-Dev] listcomps vs. for loops [Python-Dev] listcomps vs. for loopsAahz aahz at pythoncraft.com
Wed Oct 22 09:49:13 EDT 2003
On Tue, Oct 21, 2003, Guido van Rossum wrote:
>
> If you're talking about making
> 
>   x = None
>   for x in R: pass
>   print x # last item of R
> 
> illegal, forget it.  That's too darn useful.

Not illegal, but perhaps for 3.0 we should consider making that print
display "None".  The question is to what extent Python should continue
having unified semantics across constructs.  While I agree that listcomps
should definitely have a local scope ("expressions should not have
side-effects"), I think that there would be advantages to the control
variable in a for loop also having local scope that are magnified by
having compatible semantics between listcomps and for loops.  In other
words, consider

    x = None
    [x for x in R]
    print x

Why should the two behave differently?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4