How can I speed this function up?
tjreedy at udel.edu
Sat Nov 18 03:58:21 CET 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 is 'ELEMENT':
Testing for equality with 'is' is a bit of a cheat since it is
but since you have a somewhat unfair constraint ....
> out.write("%s %06d " % (i, i))
Since i is tested to be "ELEMENT', this should be the same as
out.write("ELEMENT %06d " % i)
which saves constructing a tuple as well as an interpolation.
> for j in i:
> out.write("%d " % (j))
More information about the Python-list