By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

numbering sequence

P: 2
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
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
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

P: 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.