0
python string~replace multiple character at once? Say I have string "AAGCCT" ,I want to replace 'A'with'T' and 'T'with'A' and 'C'with'G' and 'G'with'C'. So the output should be "TTCGGA"
3 Respuestas
+ 1
you can do it with some helper characters. replace A with R, then replace T with A and then replace R with T. Do the same for C G
+ 1
#this code was taken from www.onlamp.com site
def complements (s):
basecomplements = { 'A' : 'T' , 'C' : 'G' , 'G' : 'C' , 'T' : 'A'}
letters= list (s)
letters = [basecomplements [base] for base in letters]
return ''.join (letters)
print(complements('AAGCTGCCCT'))
0
Thanks