Python complaints

Greg Ewing greg.ewing at compaq.com
Wed Dec 15 08:05:17 EST 1999


Charles Boncelet wrote:
> 
> But the savings is minimal versus normal Python
> 
> fx = []
> for a in x:
>     fx.append(a**2)
> 
> Am I missing something?

Well, it's a matter of opinion, obviously, but I think the
difference is rather more than minimal. The list comprehension
syntax is more declarative -- it says what result is required
without dwelling on the details of how to get it. It has the
rare quality of being more concise without being more obscure.
Also it's an expression, so it can be embedded in other
expressions, whereas the above equivalent can't.

Greg



More information about the Python-list mailing list