<p>使用<code>zip</code>:</p>
<pre><code>>>> a = [0,13,26,39]
>>> b = [12,25,38,51]
>>> strs = 'If you are done with the file, move to the command area across from the file name in the RL screen and type'
>>> spl = strs.split()
>>> for x,y in zip(a,b):
... print spl[x:y]
...
['If', 'you', 'are', 'done', 'with', 'the', 'file,', 'move', 'to', 'the', 'command', 'area']
['from', 'the', 'file', 'name', 'in', 'the', 'RL', 'screen', 'and', 'type']
[]
[]
</code></pre>
<p><code>zip</code>返回元组列表,其中每个元组包含传递给它的iterables中相同索引上的项:</p>
<pre><code>>>> zip(a,b)
[(0, 12), (13, 25), (26, 38), (39, 51)]
</code></pre>
<p>如果您想要内存高效的解决方案,请使用<code>itertools.izip</code>,因为它返回一个迭代器。你知道吗</p>
<p>如果要从切片列表创建字符串,可以使用<code>str.join</code>:</p>
<pre><code>for x,y in zip(a,b):
print " ".join(spl[x:y])
...
If you are done with the file, move to the command area
from the file name in the RL screen and type
</code></pre>
<p><strong>更新:</strong>创建<code>a</code>和<code>b</code>:</p>
<pre><code>>>> n = 5
>>> a = range(0, 13*n, 13)
>>> b = [ x + 12 for x in a]
>>> a
[0, 13, 26, 39, 52]
>>> b
[12, 25, 38, 51, 64]
</code></pre>