Does it have to be python? Bash command
comm does exactly what you need:
comm -12 <(sort file1) <(sort file2)
I don't know how fast a Python loop would be, but the above code takes about 0.05 seconds for 2 files with 50,000 lines each.
i use windows so yes it has to be python
yes it is very very slow for files above 1,000,000 lines
when i want to compare a files with +10,000,000 lines to other 2,000,000 lines (i had to cancel and close the script

)
i sort the first file then i split it to many small files 100k lines each (and was very very slow too

)
at some point python did not help my requirement