Generator expression parenthesis mixed with function call ones

Gabriel Genellina gagsl-py2 at
Wed Mar 7 22:17:26 CET 2007

En Wed, 07 Mar 2007 15:21:57 -0300, Laurent Pointal  
<laurent.pointal at> escribió:

> Gabriel Genellina wrote:
>> En Wed, 07 Mar 2007 12:53:43 -0300, Laurent Pointal
>> <laurent.pointal at> escribió:
>>> Why does Python allow generator expression parenthesis to be mixed with
>>> function call parenthesis when there is only one parameter ?
>Beginners generally know about list-comprehensions and associate the
> syntax "x for x in asequence" to a list expression. I'm not sure that

But list comprehensions have [] around... When you don't see the [], you  
should think "this is something different"...

> reading a "f(i for i in range(20))" they understand that they are dealing
> with a different object kind.


> If function f start by a if len(myparameter)...
>   TypeError: len() of unsized object
> If function f goes among its parameter with "for x in myparameter" more  
> than
> once, other loops goes throught an empty loop.

Then he thinks "Something is wrong!", and reads some Python books, or asks  
here, and somebody will point him to the Python Tutorial, section 9.11:

>>> IMHO this should be forbidden, usage must not be different when there  
>>> is only one parameter and when there are more parameters.

If you want to review the original discussion on how to spell a generator  
expression (called "accumulator display" by that time) see

Gabriel Genellina

More information about the Python-list mailing list