擅长:python、mysql、java
<p>如果“相似”是指元组的第一个索引相同,则类似于:</p>
<pre><code>d = {'Books' : [(2,2), (3,4), (7,19)],
'CDs' : [(1,9), (3,5), (3,6), (10,9)],
'Toys' : [(0,1), (2,8), (3,3), (4,6)]}
def find_when(d, n):
return {k: [el for el in v if el[0] == n] for k, v in d.iteritems()}
print find_when(d, 3)
# {'CDs': [(3, 5), (3, 6)], 'Books': [(3, 4)], 'Toys': [(3, 3)]}
</code></pre>