擅长:python、mysql、java
<p>嵌套循环不会实现多个可重用项的并行迭代。当您希望将一个iterable中的每个元素与另一个iterable中的每个元素(“笛卡尔积”)配对时,它们非常适合。对于并行(成对/元组)迭代,使用<a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>for x in zip(list1, list2, list3):
print("".join(map(str, x)))
# ad1
# be2
# cf3
</code></pre>
<p>一些文件:</p>
<ul>
<li><a href="https://docs.python.org/3/library/functions.html#map" rel="nofollow noreferrer">^{<cd2>}</a></li>
<li><a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow noreferrer">^{<cd1>}</a></li>
<li><a href="https://docs.python.org/3/library/stdtypes.html#str.join" rel="nofollow noreferrer">^{<cd4>}</a></li>
<li><a href="https://docs.python.org/3/library/stdtypes.html#str" rel="nofollow noreferrer">^{<cd5>}</a></li>
</ul>