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/038918.html below:

[Python-Dev] Re: accumulator display syntax

[Python-Dev] Re: accumulator display syntaxGuido van Rossum guido at python.org
Fri Oct 17 17:48:33 EDT 2003
> >     >>> [(a,b) for (a,b) in zip(range(5), range(10))]
> >     [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]
> >     >>> [a,b for (a,b) in zip(range(5), range(10))]
> >       File "<stdin>", line 1
> >         [a,b for (a,b) in zip(range(5), range(10))]
> >                ^
> >     SyntaxError: invalid syntax
> 
> This one has bitten me several times.
> 
> When it does, I discover the error quickly due to the syntax error,

Generally, when we talk about something "biting", we mean something
that *doesn't* give a syntax error, but silently does something quite
different than what you'd naively expect.

This was made a syntax error specifically because of this ambiguity.

> but it would be bad if this became valid syntax and returned a list
> [a,X] where X is an iterator.  I don't think you could count on this
> getting caught by a being unbound, because often the variables in
> list comprehensions can be single letters that shadow previous
> bindings.

No, [a,X] would be a syntax error if X was an iterator comprehension.

--Guido van Rossum (home page: http://www.python.org/~guido/)

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