top of page

Problem:

In DNA strings, symbols 'A' and 'T' are complements of each other, as are 'C' and 'G'.

 

The reverse complement of a DNA string s is the string c formed by reversing the symbols of s, then taking the complement of each symbol (e.g., the reverse complement of "GTCA" is "TGAC").

​

Given:  A DNA string s of length of at most 1000 base pairs

​

Return: The reverse complement 

​

Sample Dataset: AAAACCCGGT

​

Sample Output:  ACCGGGTTTT

Solution:

First let's understand how to make a reverse complement:

1

AAAACCCGGT

reverse the original strand

2

TGGCCCAAAA

complement the reversed strand

3

ACCGGGTTTT

voila!

So now that we know what to do first let's reverse the strand using a backward slice:

< >

x = "AAAACCCGGT"

​

reverse = x[::-1]

Now we create that will match each base to it's complementary base and print it out:

< >

x = "AAAACCCGGT"

​

reverse = x[::-1]

​

dict = {"A":"T", "T":"A", "C":"G", "G": "C"}

output = ""

​

for base in reverse:

output += dict.get(base)

​

print(output)

Output:

ACCGGGTTTT

Copy and paste the output you get from running your code on the sample data onto the Rosalind answer terminal and submit. Annnd get yourself a cookie!

Subscribe to my mailing list and never miss a blogpost or new puzzle!

  • White Instagram Icon

Thanks for submitting!

bottom of page