[Tutor] ideas on how to process a file

Kent Johnson kent37 at tds.net
Fri Apr 10 19:37:11 CEST 2009


On Fri, Apr 10, 2009 at 1:12 PM, Sander Sweers <sander.sweers at gmail.com> wrote:
> results = []
>
> for line in text_file:
>    if 'FULLNAME' in line and line not in results:
>        results.append(line)
>        write_file.write(line)

In general it is better to use a set for this kind of application, it
will have much better performance if the number of lines is large.

results = set()
...
  results.add(line)

Kent


More information about the Tutor mailing list