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"

17th Aug 2016, 3:42 PM
sola
sola - avatar
3 ответов
+ 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
17th Aug 2016, 9:01 PM
‫Ido Tal
‫Ido Tal - avatar
+ 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'))
17th Aug 2016, 9:21 PM
‫Ido Tal
‫Ido Tal - avatar
0
Thanks
17th Aug 2016, 9:12 PM
sola
sola - avatar