Exercise 1 solution data = """>alpha first GGCCGGAT TATTAAGC >beta second atatatat atGCat >gamma third ACGTNNACGT >delta fourth GGGGCCCC """ def parse_fasta(text): records = {} name = None for line in text.splitlines(): line = line.strip() if not line: continue if line.startswith(">"): name = line[1:].split()[0] records[name] = "" else: records[name] += line.upper() return records def gc(s): return (s.count("G") + s.count("C")) / len(s) best = None for name, s in parse_fasta(data).items(): bad = sorted(set(s) - set("ACGT")) if bad: print(name, len(s), "skipped, unexpected characters:", bad) continue print(name, len(s), round(gc(s), 3)) if best is None or gc(s) > best[1]: best = (name, gc(s)) print("highest GC:", best[0], best[1]) Output: alpha 16 0.5 beta 14 0.143 gamma 10 skipped, unexpected characters: ['N'] delta 8 1.0 highest GC: delta 1.0 Reading it: the parser joins the wrapped lines of each record and upper-cases them, so the lower-case record is read the same way as the others. A record with a character outside A, C, G and T (here N, an unknown base) is skipped with a message instead of giving a misleading GC value. The record made only of G and C scores 1.0 and wins.