[Tutor] Printing Complimentary strand of the DNA sequence:

Mihir Kharate kharatemihir at gmail.com
Sun Oct 6 19:59:39 EDT 2019


Thanks @Mats Wichmann , I tried all the suggestions for returning the
output I wanted. They all worked great. Although removing the second
for loop returned an error. So I removed the extra indentation and
then it worked fine.
Also, I think that by default, when I assign a variable to input
something, the input is stored as a string unless maybe when it is a
number.

@Alan Gauld , thank you for the suggestion of the maketrans function!
It worked out great, with relatively less code.


On Fri, Oct 4, 2019 at 1:23 PM Alan Gauld via Tutor <tutor at python.org> wrote:
>
> On 04/10/2019 11:39, Mihir Kharate wrote:
>
> > (In a DNA sequence, the base 'A' binds to the base 'T' and 'C' binds
> > to 'G'. These base letters are compliments of each other). So the
> > expected output for a 'ATTGC' should be 'TAACG'
> Look at the translate method of strings combined with the
> maketrans() function....
>
>
> >>> table = str.maketrans('ATCG','TAGC')
> >>> 'AGTCAGACT'.translate(table)
> 'CTGACTCAG'
>
> Is that what you want?
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list