<p>我想知道dictionary keys()方法何时是必需的。这是我的密码。在</p>
<pre><code>rawFeats = [(0, 'mouse'), (1, 'black'), (0, 'cat'), (1, 'tabby'), (2, 'mouse')]
OHEDict = {(0, 'cat'): 1, (1, 'tabby'): 4, (2, 'mouse'): 5}
indices = {OHEDict[i]:1.0 for i in rawFeats if i in OHEDict}
indices1 = {OHEDict[i]:1.0 for i in rawFeats if i in OHEDict.keys()}
print "indices = {0}\nindices1 = {1}".format(indices, indices1)
</code></pre>
<p>输出为:</p>
^{pr2}$
<p>我可以理解indicates1工作得很好,因为<code>(0, 'cat')</code>是其中一个关键,但是为什么索引的结果是相同的呢?如有任何提示,我们将不胜感激。顺便说一句,对于大数据集来说,指数的性能远远好于指标1。在</p>