<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
how long does this take ?
<p><tt>if ergline not in ergfield:</tt>
<br><tt> ergfield.append(ergline)</tt>
<p>If the order is not important, could you use a dictionary? e.g.
<p><tt>ergfield = {} # dictionary</tt><tt></tt>
<p><tt># more code...</tt><tt></tt>
<p><tt>ergfield[ergline] = ergline</tt><tt></tt>
<p>or
<p><tt>if not ergfield.has_key(ergline)</tt>
<br><tt> ergfield[ergline] = ergline</tt>
<br>
<p>Stephen D Evans
<br>
<p>Werner Hoch wrote:
<blockquote TYPE=CITE>Hello,
<p>I wrote a little programm parsing two textfiles together.
<br>The result is a list without uniq entries:
<p>So i wrote this to check if the entry already exists:
<br>--------
<br>if ergfield.count(ergline) == 0:
<br> ergfield.append(ergline)
<br>---------
<br>execution time is about 45 seconds
<p>an then I tried a second statment which is twice as fast as the first
one:
<br>------------
<br>try:
<br> ergfield.index(ergline)
<br>except:
<br> ergfield.append(ergline)
<br>------------
<br>execution time is about 21 seconds
<p>I don't like the second solution because it uses the exeption handling
like
<br>a if statement!
<br>Are there better ways to do this?
<p>best regards
<br>werner
<p>BTW: how can I convert an integer to a string?
<br>--
<br>werner.ho@gmx.de</blockquote>
</html>