擅长:python、mysql、java
<p>使用邮编:</p>
<pre><code>>>> t1 = ["abc","def","ghi"]
>>> t2 = [1,2,3]
>>> list(zip(t1,t2))
[('abc', 1), ('def', 2), ('ghi', 3)]
# Python 2 you do not need 'list' around 'zip'
</code></pre>
<p>如果不希望重复项目,并且不关心顺序,请使用集合:</p>
<pre><code>>>> l1 = ["abc","def","ghi","abc","def","ghi"]
>>> l2 = [1,2,3,1,2,3]
>>> set(zip(l1,l2))
set([('def', 2), ('abc', 1), ('ghi', 3)])
</code></pre>
<p>如果要按顺序进行uniquify:</p>
<pre><code>>>> seen=set()
>>> [(x, y) for x,y in zip(l1,l2) if x not in seen and (seen.add(x) or True)]
[('abc', 1), ('def', 2), ('ghi', 3)]
</code></pre>