Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Read the file and get the DNA string
file = open("sample_dna.txt", "r")
dna =
# Print the original DNA string
print "DNA String: ", dna
# Create dictionary of complementing nucleobase pairs
comp_pairs = {"A" : "T", "T" : "A", "G" : "C", "C" : "G"}
complementing_strand = ""
# Generate the complementing strand
for i in range (len(dna)-1, -1, -1):
complementing_strand += comp_pairs[dna[i]]
# Print the complementing strand
print "Complement: ", complementing_strand
# End of program
Copy link

Vini2 commented Aug 11, 2017

Complementing a Strand of DNA
Solution for problem at

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment