Nebie: list question, speed

Werner Hoch werner.ho at gmx.de
Sat May 5 11:30:59 EDT 2001


Hello,

I wrote a little programm parsing two textfiles together.
The result is a list without uniq entries:

So i wrote this to check if the entry already exists:
--------
if ergfield.count(ergline) == 0:
      ergfield.append(ergline)
---------
execution time is about 45 seconds

an then I tried a second statment which is twice as fast as the first one:
------------
try:
      ergfield.index(ergline)
except:
      ergfield.append(ergline)
------------
execution time is about 21 seconds

I don't like the second solution because it uses the exeption handling like
a if statement!
Are there better ways to do this?

best regards
werner

BTW: how can I convert an integer to a string?
-- 
werner.ho at gmx.de



More information about the Python-list mailing list