How can I speed this function up?

Terry Reedy tjreedy at udel.edu
Fri Nov 17 21:58:21 EST 2006


"Chris" <cfriedl at bigpond.net.au> wrote in message 
news:kou7h.67901$rP1.39303 at news-server.bigpond.net.au...
> def write_data1(out, data):
>     for i in data:
>         if i[0] is 'ELEMENT':

Testing for equality with 'is' is a bit of a cheat since it is 
implementation dependent,
but since you have a somewhat unfair constraint ....

>             out.write("%s %06d " % (i[0], i[1]))

Since i[0] is tested to be "ELEMENT', this should be the same as
         out.write("ELEMENT %06d " % i[1])
which saves constructing a tuple as well as an interpolation.

>             for j in i[2]:
>                 out.write("%d " % (j))
>             out.write("\n")

tjr






More information about the Python-list mailing list