mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-24 05:21:09 +00:00
daa1c7529a
* ci: Add `B023` to `.flake8` ignores * refactor: Return `bool`/raise Exception * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * revert: Remove previous branch commit * Update data_structures/binary_tree/segment_tree_other.py Co-authored-by: Christian Clauss <cclauss@me.com> * feat: Apply `__repr__` changes * chore: Fix failing tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update data_structures/binary_tree/segment_tree_other.py Co-authored-by: Christian Clauss <cclauss@me.com> * test: Fix doctests * random.choice(population_score[:N_SELECTED])[0] * Update basic_string.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
32 lines
556 B
Python
32 lines
556 B
Python
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")
|
|
Traceback (most recent call last):
|
|
...
|
|
ValueError: Invalid Strand
|
|
"""
|
|
|
|
if len(re.findall("[ATCG]", dna)) != len(dna):
|
|
raise ValueError("Invalid Strand")
|
|
|
|
return dna.translate(dna.maketrans("ATCG", "TAGC"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import doctest
|
|
|
|
doctest.testmod()
|