numbering of members of a sequence
I need additional python codes that will number the left column of the output below like I have shown in the right column: The codes here just divides the sequence into 3s. Now I want to number them from 1 to the last as I have done manually in the right column.
cds = "atgagtgaacgtctgagcattaccccgctggggcc开发者_JS百科gtatatcggcgcacaataa"
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
cds = "atgagtgaacgtctgagcattaccccgctggggccgtatatcggcgcacaataa"
for num, i in enumerate(range(0,len(cds),3)):
print cds[i:i+3], num + 1
Not sure that this is what you want, but:
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
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
>>>
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]
精彩评论