is list comprehension necessary?

Roy Smith roy at panix.com
Wed Oct 27 13:37:14 CEST 2010


Andre Alexander Bell <p... at andre-bell.de> wrote:
>> I occasionally use LCs, if they seem useful. However, what I
>> don't like about LCs is that they 'look-like' being a closed scope
>> [...]
> 

antingrick <rantingrick at gmail.com> wrote:
> I must admit you make a good point here however the only time that
> will slip you up is when you first experienced the Python LC syntax.
> After a few "hello world" LC's you'll begin to love and understand
> them completely.

I agree.  I resisted LCs when they first came out, passing them off as 
unnecessary, confusing, etc.  Eventually, I came to be comfortable with 
them and use them often.

I did not realize just how far my mind-change had gone until just 
yesterday when I was hacking on some PHP code.  I wrote:

$values = array();
foreach ($ids as $id) {
   $values[] = $id;
}

and found myself asking my office-mate, "Hey, Chris, does PHP have list 
comprehensions?"  I was bummed to discover that it does not.



More information about the Python-list mailing list