From cbf3c6140aafefbaef7186e0cb97d0758b1d38b2 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Mon, 5 Sep 2022 04:51:11 +0300 Subject: [PATCH] add the dna algorithm (#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. --- strings/dna.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 strings/dna.py diff --git a/strings/dna.py b/strings/dna.py new file mode 100644 index 000000000..46e271d68 --- /dev/null +++ b/strings/dna.py @@ -0,0 +1,26 @@ +import re + + +def dna(dna: str) -> str: + + """ + 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") + 'Invalid Strand' + """ + + r = len(re.findall("[ATCG]", dna)) != len(dna) + val = dna.translate(dna.maketrans("ATCG", "TAGC")) + return "Invalid Strand" if r else val + + +if __name__ == "__main__": + __import__("doctest").testmod()