List comprehension confusion...

Erik Max Francis max at alcyone.com
Sat Feb 1 23:07:26 EST 2003


Andrew Dalke wrote:

> results = []
> for term in data:
>     results.append(term.some_field)
> 
> Here's the list comprehension solution
> 
> results = [term.data for term in data]

Nitpicking time, you meant term.some_field there instead of term.data.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ A man cannot be comfortable without his own approval.
\__/ Mark Twain
    Sade Deluxe / http://www.sadedeluxe.com/
 The ultimate Sade encyclopedia.




More information about the Python-list mailing list