https://en.wikipedia.org/wiki/DNA Returns the second side of a DNA strand >>> dna("GCTA") 'CGAT' >>> dna("ATGC") 'TACG' >>> dna("CTGA") 'GACT' >>> dna("GFGG") Traceback (most recent call last): ... ValueError: Invalid Strand
(dna: str)
| 2 | |
| 3 | |
| 4 | def dna(dna: str) -> str: |
| 5 | """ |
| 6 | https://en.wikipedia.org/wiki/DNA |
| 7 | Returns the second side of a DNA strand |
| 8 | |
| 9 | >>> dna("GCTA") |
| 10 | 'CGAT' |
| 11 | >>> dna("ATGC") |
| 12 | 'TACG' |
| 13 | >>> dna("CTGA") |
| 14 | 'GACT' |
| 15 | >>> dna("GFGG") |
| 16 | Traceback (most recent call last): |
| 17 | ... |
| 18 | ValueError: Invalid Strand |
| 19 | """ |
| 20 | |
| 21 | if len(re.findall("[ATCG]", dna)) != len(dna): |
| 22 | raise ValueError("Invalid Strand") |
| 23 | |
| 24 | return dna.translate(dna.maketrans("ATCG", "TAGC")) |
| 25 | |
| 26 | |
| 27 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected