[Python-Dev] accumulator display syntax

Ian Bicking ianb at colorstudy.com
Tue Oct 21 15:08:30 EDT 2003


On Tuesday, October 21, 2003, at 01:58 PM, Raymond Hettinger wrote:
> At one time, I got a lot of feedback on this from comp.lang.python.
> Just about everyone found the brackets to be helpful and not 
> misleading,
> the immediate presence of "yield" was more than enough to signal that
> an iterator was being returned instead of a list:
>
> 	g = [yield (len(line),line)  for line in file  if len(line)>5]

FWIW, that g is an iterator is *far* less surprising than the fact that 
yield turns a function into a generator.  If it's okay that a yield in 
the body of a function change the function, why can't a yield in the 
body of a list comprehension change the list comprehension?  It's a lot 
more noticeable, and people should know that "yield" signals something 
a little more tricky is going on.  Also has good symmetry with the 
current meaning of yield.

--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org




More information about the Python-Dev mailing list