[Tutor] optimization: faster than for
Eike Welk
eike.welk at gmx.net
Sun Jul 1 19:50:19 CEST 2007
On Sunday 01 July 2007 06:17, elis aeris wrote:
> The for version, as claimed by
>
> http://www.python.org/doc/essays/list2str.html
The fastest version of the algorithm is this one:
In [4]:import array
In [5]:def f7(list):
.5.: return array.array('B', list).tostring()
.5.:
In [6]:f7([97, 98, 99])
Out[6]:'abc'
The implicit loop is the "tostring" function. It is written in C and
it happens to perform the desired algorithm. So there is nothing
magical about "implicit loops". It just means: Find a library
function that is written in C and that performs your task.
For manipulating images it means: Find some operations in PIL that do
what you want, and don't look at pixel values.
Kind regards,
Eike.
More information about the Tutor
mailing list