Reverse Complement

Foundational Python Foundations DNA Reverse Complement Double Helix
Significance:

DNA is double-stranded and antiparallel, so any tool touching real genomic data — primer design,
aligners like BWA and Bowtie, restriction mapping — must be able to compute the reverse
complement to check both strands. PCR primer design cannot be done correctly without it.

Statement

Given a DNA string, return its reverse complement: take the complement of each base
(A to T, T to A, C to G, G to C), then reverse the result.

Print the reverse complement on one line.

Input — read from standard input
Variable Type Description
s
line 1
str The DNA sequence to reverse-complement
1 <= len(s) <= 1000, uppercase A, C, G, T only

These variables are already read for you in the starter code on the right.

Output

str the reverse complement of s, on one line

Sample Cases
Sample 1
Input
AAAACCCGGT
Expected Output
ACCGGGTTTT
Complement of AAAACCCGGT is TTTTGGGCCA; reversing gives ACCGGGTTTT.
Sample 2
Input
ACGT
Expected Output
ACGT
A palindromic case — its own reverse complement.

Submit also runs your code against 4 hidden test cases. Hidden inputs are never shown — if one fails you'll get its number and a description of the mismatch, not the data.

Constraints
  • 1 <= length(s) <= 1000
  • Uppercase A, C, G, T only
Further Reading
  • Complementing then reversing gives the same answer as reversing then complementing.
  • Python's str.maketrans() plus [::-1] does this in two steps.

My Notes
Log in to save personal notes.
Console output will appear here when you click Run Code or Submit...
Expected: s (str)
Next Problem
Hamming Distance