From my limited understanding of python I believe loading bits.txt as a set would dramatically increase the search speed bit_addresses = set(line.strip() for line in open('Bits.txt'))