擅长:python、mysql、java
<p>一个很好的解决方案是使用列表理解并将列表转换为一个集合:</p>
<pre><code>toCrawl=[["http://website.html",0],["http://websiteAlt.html",1],["http://websiteAlt.html",1]]
newLinks = set([item[0] for item in toCrawl])
print(newLinks)
</code></pre>
<p><strong>输出</strong></p>
<pre><code>{'http://website.html', 'http://websiteAlt.html'}
</code></pre>
<p>请注意,为了删除重复项,集合似乎是一个很好的做法,这来自<a href="https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset" rel="nofollow noreferrer">documentation</a>:</p>
<blockquote>
<p>A set object is an unordered collection of distinct hashable objects.
Common uses include membership testing, removing duplicates from a
sequence, and computing mathematical operations such as intersection,
union, difference, and symmetric difference. (For other containers see
the built-in dict, list, and tuple classes, and the collections
module.)</p>
</blockquote>