Newbie: list comprehension troubles..
tjreedy at udel.edu
Mon Aug 24 02:05:38 CEST 2009
Chris Rebert wrote:
> On Sun, Aug 23, 2009 at 4:27 PM, mm<mattaman at gmail.com> wrote:
>> Hi, I'm trying to replace this...
>> # this works but there must be a more pythonic way, right?
'Pythonic' is readable, if nothing else
>> tlist = 
>> for obj in self.objs:
>> t = obj.intersect(ray)
>> if (t != None):
This, to me, is more readable than the lc replacement.
>> with a list comprehension- can it be done?
> tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in
> self.objs) if pair is not None]
> Should it be done? Probably not. It's less readable and less efficient.
More information about the Python-list