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))
>
>
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.
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
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
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)
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
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