How can I speed this function up?

Terry Reedy tjreedy at
Sat Nov 18 03:58:21 CET 2006

"Chris" <cfriedl at> wrote in message 
news:kou7h.67901$rP1.39303 at
> 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")


More information about the Python-list mailing list