擅长:python、mysql、java
<pre><code>>>> import itertools
>>> ''.join(map(str, itertools.chain.from_iterable(zip(list1, list2))))
1one2two3three4four5five'
</code></pre>
<p><strong>说明:</strong></p>
<ul>
<li><p><code>zip(list1, list2)</code>创建一个列表,其中包含两个列表中匹配元素的元组:</p>
<pre><code>>>> zip(list1, list2)
[(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four'), (5, 'five')]
</code></pre></li>
<li><p><a href="http://docs.python.org/2/library/itertools.html#itertools.chain.from_iterable" rel="nofollow">^{<cd2>}</a>展开嵌套列表:</p>
<pre><code>>>> list(chain.from_iterable(zip(list1, list2)))
[1, 'one', 2, 'two', 3, 'three', 4, 'four', 5, 'five']
</code></pre></li>
<li><p>现在我们需要确保只有字符串,所以我们使用<code>map()</code>将<code>str()</code>应用于所有项</li>
<li>最后<code>''.join(...)</code>将列表项合并为一个不带分隔符的字符串。</li>
</ul>