Rosalind: Transcribing DNA into RNA

Python

Solution 1

1
2
3
4
5
COMPLEMENTARY = {"A": "T", "C": "G", "G": "C", "T": "A"}

def reverse_complement(dna):
    revc = str.maketrans(COMPLEMENTARY)
    return dna[::-1].translate(revc)

Solution 2

1
2
3
4
5
6
7
COMPLEMENTARY = {"A": "T", "C": "G", "G": "C", "T": "A"}

def reverse_complement(dna):
    def _reverse_complement(dna):
        for nt in reversed(dna):
            yield COMPLEMENTARY[nt]
    return "".join(_reverse_complement(dna))
0%