Skip to content

Dna enhancement #6713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions strings/dna.py

This file was deleted.

26 changes: 26 additions & 0 deletions strings/dna_matching_strand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def dna_matching_strand(dna: str) -> str:
"""
https://en.wikipedia.org/wiki/DNA
Returns the second side of a DNA strand

>>> dna_matching_strand("GCTA")
'CGAT'
>>> dna_matching_strand("ATGC")
'TACG'
>>> dna_matching_strand("CTGA")
'GACT'
>>> dna_matching_strand("GFGG")
Traceback (most recent call last):
...
ValueError: GFGG is not a valid strand of DNA
"""
dna = dna.upper()
if not all(c in "ATGC" for c in dna):
raise ValueError(f"{dna} is not a valid strand of DNA")
return dna.translate(str.maketrans("ATGC", "TACG"))


if __name__ == "__main__":
import doctest

doctest.testmod()