Skip to content

Commit cbf3c61

Browse files
authored
add the dna algorithm (TheAlgorithms#6323)
* adding the dna algorithm * following bot recommendations following bot recommendations for the indentation * following bot recommendations following bot recommendations regarding indentation [ again ] * following bot recommendations following bot recommendations regarding indentation [ again. ] * following bot recommendations following bot recommendations.
1 parent b1818af commit cbf3c61

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: strings/dna.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import re
2+
3+
4+
def dna(dna: str) -> str:
5+
6+
"""
7+
https://en.wikipedia.org/wiki/DNA
8+
Returns the second side of a DNA strand
9+
10+
>>> dna("GCTA")
11+
'CGAT'
12+
>>> dna("ATGC")
13+
'TACG'
14+
>>> dna("CTGA")
15+
'GACT'
16+
>>> dna("GFGG")
17+
'Invalid Strand'
18+
"""
19+
20+
r = len(re.findall("[ATCG]", dna)) != len(dna)
21+
val = dna.translate(dna.maketrans("ATCG", "TAGC"))
22+
return "Invalid Strand" if r else val
23+
24+
25+
if __name__ == "__main__":
26+
__import__("doctest").testmod()

0 commit comments

Comments
 (0)