Roulette wheel
Aahz
aahz at pythoncraft.com
Wed Mar 18 12:34:57 EDT 2009
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).
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"Programming language design is not a rational science. Most reasoning
about it is at best rationalization of gut feelings, and at worst plain
wrong." --GvR, python-ideas, 2009-3-1
More information about the Python-list
mailing list