A Mountain of Perl Books + Python Advocacy

Andrew Dalke dalke at acm.org
Tue May 9 21:38:24 EDT 2000

Ben Wolfson wrote:
>for line in lines:
>   if line not in uniqlines:
>      uniqlines.append(line)
>      out.write(line)

Since you've sorted the lines, you don't need the "line not in ..."
That gives you order n-squared performance.  Since you already sorted
the lines, a better one is:

prev = None
for line in lines:
  if line != prev:
    prev = line


More information about the Python-list mailing list