Roulette wheel
mattia
gervaz at gmail.com
Wed Mar 18 16:14:35 EDT 2009
Il Wed, 18 Mar 2009 09:34:57 -0700, Aahz ha scritto:
> In article <gop0se$7hu$01$1 at news.t-online.com>, Peter Otten
> <__peter__ at web.de> wrote:
>>mattia wrote:
>>>
>>> cpop += [nchromosome1] + [nchromosome2]
>>
>>I'd write that as
>>
>>cpop.append(nchromosome1)
>>cpop.append(nchromosome2)
>>
>>thus avoiding the intermediate lists.
>
> You could also write it as
>
> cpop += [nchromosome1, nchromosome2]
>
> which may or may not be faster, substituting one attribute lookup, one
> list creation, and one method call for two attribute lookups and two
> method calls. I shan't bother running timeit to check, but I certainly
> agree that either your version or mine should be substituted for the
> original, depending on one's esthetics (meaning that I doubt there's
> enough performance difference either way to make that the reason for
> choosing one).
Yeah, and I believe that we can say the same for:
1 - t = [x*2 for x in range(10)]
2 - t = list(x*2 for x in range(10))
or not?
More information about the Python-list
mailing list