List Comprehension Syntax

Andrea Griffini agriff at tin.it
Sat Jul 10 15:42:34 EDT 2004


On 10 Jul 2004 16:41:16 +0300, Ville Vainio <ville at spammers.com>
wrote:

>I think you'll find that you don't need to sacrifice any of your old
>models or even aesthetic preferences to appreciate LCs. 

I'm quite new to python, and I found LC quite simple to understand
and powerful. The only "suprising" part for me was that the looping
variable is not local... I slipped on that a couple of times.
A list comphrension is very "local" in my mind ... I would say that
[x*x for x in xrange(10)] is just a list of perfect squares, but
instead it's not... it's that AND the assignment to x of the value 9.

Andrea 



More information about the Python-list mailing list