Srinivas Iyyer wrote:
> Hello group:
>
> Is there a 'substitute' function in 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. Do this with string.maketrans():
>>> import string
>>> xlate = string.maketrans('AGTC', 'TCAG')
Next use the translation table to translate the string of interest:
>>> 'AAGTTC'.translate(xlate)
'TTCAAG'
Kent
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor