Re: [Tutor] Loop optimization

2007-09-15 Thread Kent Johnson
wormwood_3 wrote: > Kent, > > You replied with the following some time ago regarding a question I asked > about optimizing a loop: > >>> You should try an optimized for loop: >>> append_ = self.potdomains.append_ >>> s1_ = suffix1 >>>

Re: [Tutor] Loop optimization

2007-09-15 Thread wormwood_3
Kent, You replied with the following some time ago regarding a question I asked about optimizing a loop: >> You should try an optimized for loop: >> append_ = self.potdomains.append_ >> s1_ = suffix1 >> s2_ = suffix2 >>

Re: [Tutor] Loop optimization

2007-08-20 Thread Kent Johnson
wormwood_3 wrote: > I ran a few tests, with the following results: > > 1. Timing using the time module: >* Using for loop, src code: > import time > start = time.time() > for word in self.dictcontents: > se

Re: [Tutor] Loop optimization

2007-08-20 Thread wormwood_3
I ran a few tests, with the following results: 1. Timing using the time module: * Using for loop, src code: import time start = time.time() for word in self.dictcontents: self.potdomains.append(word + suffix

Re: [Tutor] Loop optimization

2007-08-20 Thread wormwood_3
>I think what you have is pretty clear. I can't think of a way to do this >with a single list comprehension because you add two items to the list >each time through the loop. You could use a list comp and a generator >expression, but the order of entries in the result will be different: >self.po

Re: [Tutor] Loop optimization

2007-08-20 Thread Kent Johnson
wormwood_3 wrote: > Hello tutors, > > I am trying to understand the best cases in which to use for loops, list comprehensions, generators, and iterators. I have a rather simple process that I made initially as a for loop: > > self.potdomains = [] > for word in self.dictcontents: >

[Tutor] Loop optimization

2007-08-20 Thread wormwood_3
Hello tutors, I am trying to understand the best cases in which to use for loops, list comprehensions, generators, and iterators. I have a rather simple process that I made initially as a for loop: self.potdomains = [] for word in self.dictcontents: self.potdomains.a