from sys import argv f = open(argv[1], 'r') name1 = name2 = "" seq1 = seq2 = "" for line in f: if line.startswith("# 1:"): name1 = line.split(":")[1].strip() elif line.startswith("# 2:"): name2 = line.split(":")[1].strip() elif not line.startswith("#") and line.strip(): parts = line.split() if len(parts) >= 3: if parts[0] == name1: seq1 += parts[2] elif parts[0] == name2: seq2 += parts[2] f.close() indels1 = len("".join(c if c == '-' else ' ' for c in seq1).split()) indels2 = len("".join(c if c == '-' else ' ' for c in seq2).split()) print(name1, indels1) print(name2, indels2) print("Total", indels1 + indels2)