擅长:python、mysql、java
<pre><code>>>> L = [1, "term1", 3, "term2", 4, "term3", 5, "termN"]
# Create an iterator
>>> it = iter(L)
# zip the iterator with itself
>>> zip(it, it)
[(1, 'term1'), (3, 'term2'), (4, 'term3'), (5, 'termN')]
</code></pre>
<p>你想一次分三组吗?</p>
<pre><code>>>> zip(it, it, it)
</code></pre>
<p>一次要对N个项目进行分组?</p>
<pre><code># Create N copies of the same iterator
it = [iter(L)] * N
# Unpack the copies of the iterator, and pass them as parameters to zip
>>> zip(*it)
</code></pre>