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 ss is the string scsc formed by reversing the symbols of ss, then taking the complement of each symbol (e.g., the reverse complement of "GTCA" is "TGAC").
Given: A DNA string ss of length at most 1000 bp.
Return: The reverse complement scsc of ss.
Sample Dataset
AAAACCCGGT
Sample Output
ACCGGGTTTT
方法一
def reverse(seq):
dict = {'A': 'T', 'C': 'G', 'T': 'A', 'G': 'C'}
revSeqList = list(reversed(seq)) #['T', 'G', 'G', 'C', 'C', 'C', 'A', 'A', 'A', 'A']
revComSeqList = [dict[k] for k in revSeqList] # ['A', 'C', 'C', 'G', 'G', 'G', 'T', 'T', 'T', 'T']
revComSeq = ''.join(revComSeqList) # ACCGGGTTTT
return revComSeq
seq = 'AAAACCCGGT'
print (reverse(seq))