import itertools

def method():
    with open(input_file, 'r') as inf:
        with open(output_file, 'w') as ouf:
            seen = set()
for line in itertools.islice(inf, None, None, 4):
    s = line[:6] + line[-6:]
if s not in seen:
    seen.add(s)
ouf.write('{}\n'.format(s))
Improving the speed of a python script