[Python-ideas] Calling a function of a list without accumulating results

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Sep 27 05:02:00 CEST 2007


Terry Jones wrote:
> the language supports the more concise form for both
> list comprehension and genexps, so there must be a fair number of people
> who thought it was a win to allow the compact form.

The compact form *is* considerably more compact when
you're constructing a list, as it saves the initalisation
and an append call. It also permits an optimisation by
extracting a bound method for the append.

When not constructing a list, however, there's no
significant difference in source length or runtime
efficiency. So the "more compact" form wouldn't be
any more compact, just different. It would be a
spurious Other Way To Do It.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | Carpe post meridiem!          	  |
Christchurch, New Zealand	   | (I'm not a morning person.)          |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+



More information about the Python-ideas mailing list