curriculum/challenges/english/blocks/daily-coding-challenges-python/68d30845cc08266018fc46bc.md
Given a string representing a DNA sequence, return its complementary strand using the following rules:
"A", "C", "G", and "T"."A" and "T" complement each other."C" and "G" complement each other.For example, given "ACGT", return "TGCA".
complementary_dna("ACGT") should return "TGCA".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(complementary_dna("ACGT"), "TGCA")`)
}})
complementary_dna("ATGCGTACGTTAGC") should return "TACGCATGCAATCG".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(complementary_dna("ATGCGTACGTTAGC"), "TACGCATGCAATCG")`)
}})
complementary_dna("GGCTTACGATCGAAG") should return "CCGAATGCTAGCTTC".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(complementary_dna("GGCTTACGATCGAAG"), "CCGAATGCTAGCTTC")`)
}})
complementary_dna("GATCTAGCTAGGCTAGCTAG") should return "CTAGATCGATCCGATCGATC".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(complementary_dna("GATCTAGCTAGGCTAGCTAG"), "CTAGATCGATCCGATCGATC")`)
}})
def complementary_dna(strand):
return strand
def complementary_dna(strand):
complements = { "A": "T", "T": "A", "C": "G", "G": "C" }
return "".join(complements[n] for n in strand)