擅长:python、mysql、java
<p>在我看来,您正在寻找<em>最佳</em>匹配(最匹配的属性),因此我建议:</p>
<pre><code>def guess(observations, animals):
return max(list((len(observations & value), key) # most matches
for key, value in animals.items()
if observations & value # if this item had matches
) or # if _nothing_ matched
[(0, None)] # use this
)[1] # strip off the count
</code></pre>