[Tutor] substitute function
luke
rabidpoobear at gmail.com
Sun Jul 31 21:53:49 CEST 2005
Are you making a biology program Srinivas?
----- Original Message -----
From: "Kent Johnson" <kent37 at tds.net>
Cc: <tutor at python.org>
Sent: Sunday, July 31, 2005 2:46 PM
Subject: Re: [Tutor] substitute function
> 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 - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list