string.maketrans python

> For example:

> I want to substitute A with T and G with C and vice

> versa > > A -> T > G -> C > T -> A > c -> G

You can do this with the translate() method of a string. It is a two-step process.

First you have to make a translation table that defines the translation.

> >> import string

> >> xlate = string.maketrans('AGTC', 'TCAG')

Next use the translation table to translate the string of interest:

> >> 'AAGTTC'.translate(xlate) 'TTCAAG'

 

 

my example:

 

import string
a=string.maketrans('abcdefghijklmnopqrstuvwxyz','cdefghijklmnopqrstuvwxyzab')
print "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.".translate(a)
  感觉没那么智能 有点像java的replace

你可能感兴趣的:(C++,c,python,C#)