This is not an idiomatic Python code. You can easily make your Python code faster using list comprehensions. Python loops outside the comprehensions are slow. You should prefer using comprehesions and map/filter functions always when it's possible.
import sys import gzip def main(vcf): vcf = gzip.open(vcf, 'r') toks = [ line.strip().split('t') for line in vcf if not line.startswith('#')] sample_toks = [ sample.split(':') for sample in toks[9:] ] if __name__ == "__main__": main(sys.argv[1])