469,361 Members | 2,390 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,361 developers. It's quick & easy.

numbering sequence

I want additional python codes that will help me generate the second column (the column with numbers) of the output under the
codes. The codes here only generate the first column
by breaking the sequence in cds into threes. Thank you.

>>> cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcac aataa"

>>> for i in range(0,len(cds),3):
... print cds[i:i+3],
...
Atg 1
Agt 2
Gaa 3
Cgt 4
Ctg 5
Agc 6
Att 7
Acc 8
Ccg 9
Ctg 10
Ggg 11
Ccg 12
Tat 13
Atc 14
Ggc 15
Gca 16
Caa 17
Taa 18
Taa 19
Jun 14 '11 #1
2 1763
bvdet
2,851 Expert Mod 2GB
Use built-in function enumerate() in conjunction with range(). Also, I would use string formatting for the output.
Expand|Select|Wrap|Line Numbers
  1. >>> cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"
  2. >>> for j,i in enumerate(range(0,len(cds),3)):
  3. ...     print "%s %2s" % (cds[i:i+3], j+1)
  4. ...     
  5. atg  1
  6. agt  2
  7. gaa  3
  8. cgt  4
  9. ctg  5
  10. agc  6
  11. att  7
  12. acc  8
  13. ccg  9
  14. ctg 10
  15. ggg 11
  16. ccg 12
  17. tat 13
  18. atc 14
  19. ggc 15
  20. gca 16
  21. caa 17
  22. taa 18
  23. >>> 
Jun 14 '11 #2
Thanks bvdet. I have used your codes and the actually did what I wanted
Jun 14 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

18 posts views Thread by Michael Hill | last post: by
5 posts views Thread by Charles McCaffery | last post: by
1 post views Thread by Wayne Aprato | last post: by
3 posts views Thread by Chris | last post: by
5 posts views Thread by Eric E | last post: by
2 posts views Thread by booher | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.