擅长:python、mysql、java
<p>试试这个</p>
<pre><code>In [13]: [x for x in start if abs(dic[x[0]] - dic[x[1]]) < 1.0001]
Out[13]: [('david', 'lucy')]
</code></pre>
<p>这是python中的<a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a>。它将检查列表中的所有属性并比较条件<code>abs(dic[x[0]] - dic[x[1]]) < 1.0001</code>满足此条件的元素将返回。你知道吗</p>