Believe it or not, a change in two characters should make this even faster.  :)

Change the line:

    file_list = [i[:-1] for i in my_list.readlines()]

to:

    file_list = {i[:-1] for i in my_list.readlines()}


The change is to use a "set comprehension" instead of a "list
comprehension".  Sets allow membership checks in expected *constant*
time instead of *linear* time.  Try that, and compare the speed: you
should get a fairly good speedup.


See:

    https://docs.python.org/3/tutorial/datastructures.html#sets

for some more details.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to