seq = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
start = [2,9,18]
end = [6,12,20]
#output = seq[end[k]:start[k+1]]
我正在尝试 end[k] 和 start[k+1] #seq[end[k]:start[k+1]] 之间的序列
所以在这种情况下应该有2个序列。
outp1 = seq[6:9] #'GHI'
out2 = seq[12:18] #'MNOPQR'
使用zip
:
>>> seq = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>>> start = [2,9,18]
>>> end = [6,12,20]
>>> for x,y in zip(end, start[1:]):
... print seq[x:y]
...
GHI
MNOPQR
内存高效版本:
>>> from itertools import izip,islice
>>> for x,y in izip(end,islice(start,1,None)):
print seq[x:y]
...
GHI
MNOPQR
for i in range(len(end)-1):
seq[end[i]:start[i+1]]
answer:-
'GHI'
'MNOPQR'