Rosalind: Complementing a Strand of DNA

Python

Solution 1

1
2
3
4
5
6
7
8
def solution_3(dna):
    def _transcribe(dna):
        for nt in dna:
            if nt == "T":
                yield "U"
            else:
                yield nt
        return "".join(_transcribe(dna))

Solution 2

1
2
def transcribe(dna):
    return dna.replace("T", "U")

Solution 3

1
2
3
def transcribe(dna):
    transcriber = str.maketrans("T", "U")
    return dna.translate(transcriber)
0%