Re: Newbie: list comprehension troubles..

2009-08-24 Thread Francesco Bochicchio
On 24 Ago, 01:27, mm wrote: > Hi, I'm trying to replace this... > >         # this works but there must be a more pythonic way, right? >         tlist = [] >         for obj in self.objs: >             t = obj.intersect(ray) >             if (t != None): >                 tlist.append((obj,t)) > >

Re: Newbie: list comprehension troubles..

2009-08-24 Thread Bruno Desthuilliers
mm a écrit : Hi, I'm trying to replace this... # this works but there must be a more pythonic way, right? tlist = [] for obj in self.objs: t = obj.intersect(ray) if (t != None): hint 1 : this is Python, you don't need parens around conditionals.

Re: Newbie: list comprehension troubles..

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 5:09 PM, Ben Finney wrote: > Chris Rebert writes: > >> tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in >> self.objs) if pair[1] is not None] >> >> Should it be done? Probably not. [Compared to a ‘for’ suite with an >> ‘if’ suite, it's] less readable and less

Re: Newbie: list comprehension troubles..

2009-08-23 Thread Ben Finney
Chris Rebert writes: > tlist = [pair for pair in ((obj, obj.intersect(ray)) for obj in > self.objs) if pair[1] is not None] > > Should it be done? Probably not. [Compared to a ‘for’ suite with an > ‘if’ suite, it's] less readable and less efficient. I disagree on the “less efficient”, unless you

Re: Newbie: list comprehension troubles..

2009-08-23 Thread Terry Reedy
Chris Rebert wrote: On Sun, Aug 23, 2009 at 4:27 PM, mm 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)

Re: Newbie: list comprehension troubles..

2009-08-23 Thread Chris Rebert
On Sun, Aug 23, 2009 at 4:27 PM, mm wrote: > Hi, I'm trying to replace this... > >        # this works but there must be a more pythonic way, right? >        tlist = [] >        for obj in self.objs: >            t = obj.intersect(ray) >            if (t != None): >                tlist.append((obj

Newbie: list comprehension troubles..

2009-08-23 Thread mm
Hi, I'm trying to replace this... # this works but there must be a more pythonic way, right? tlist = [] for obj in self.objs: t = obj.intersect(ray) if (t != None): tlist.append((obj,t)) with a list comprehension- can it be done? Wh