序列成员的编号

时间:2011-06-14 09:25:18

标签: python numbers sequence

我需要额外的python代码,这些代码将在下面输出的左列编号,就像我在右栏中所示:这里的代码只是将序列分成3s。 现在我想将它们从1编号到最后,就像我在右栏中手动完成的那样。

cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"

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

4 个答案:

答案 0 :(得分:3)

cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"

for num, i in enumerate(range(0,len(cds),3)):
    print cds[i:i+3], num + 1

答案 1 :(得分:1)

不确定这是你想要的,但是:

cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"
for data in ((i+1, cds[i:i+3], i+1) for i in xrange(0, len(cds), 3)):
    #do something
    print data

答案 2 :(得分:0)

Here you may read about this way

>>> cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"
>>> for ind, val in enumerate(range(0,len(cds),3), start=1):
...     print cds[val:val+3].capitalize(), ind
...
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
>>>

答案 3 :(得分:0)

for item in map(lambda x,y,z: [z[0]+1,"".join([x,y,z[1]])], list(cds)[::3],list(cds)[1::3],enumerate(list(cds)[2::3])):
    print item[1].capitalize(), item[0]