擅长:python、mysql、java
<p>将<a href="http://docs.python.org/2/library/string.html#formatspec" rel="nofollow">string formatting</a>与<code>str.join()</code>和<code>zip()</code>一起使用:</p>
<pre><code>>>> list1 = [1,2,3,4,5]
>>> list2 = ["one", "two", "three", "four", "five"]
>>> "".join("{0}{1}".format(x,y) for x,y in zip(list1,list2))
'1one2two3three4four5five'
</code></pre>
<p><code>zip(list1,list2)</code>返回如下内容:
<code>[(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four'), (5, 'five')]</code>。</p>
<p>现在,对于这个列表中的每一项,我们应用字符串格式,然后使用<code>str.join()</code>连接整个生成器表达式。</p>