tags:
- code
topic: Replace
difficulty: Easy
link:
date: 2023-12-30
Problem
Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.
If you want to know more: http://en.wikipedia.org/wiki/DNA
In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". Your function receives one side of the DNA (string, except for Haskell); you need to return the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).
More similar exercise are found here: http://rosalind.info/problems/list-view/ (source)
"ATTGC" --> "TAACG"
"GTAT" --> "CATA"
def DNA_strand(dna):
comp_strand = ""
pairs = {"A": "T",
"C": "G",
"G": "C",
"T": "A"}
for char in dna:
comp_strand += pairs[char]
return comp_strand
pairs = {'A':'T','T':'A','C':'G','G':'C'}
def DNA_strand(dna):
return ''.join([pairs[x] for x in dna])
def DNA_strand(dna):
reference = { "A":"T",
"T":"A",
"C":"G",
"G":"C"
}
return "".join([reference[x] for x in dna])