我的目標是將小字典映射到大字典,並在大字典中返回一個值列表,其中包含對應的鍵字典。如何映射兩個字典中的相同項目並生成其相應鍵值的列表
x={'red':0.25, 'yellow':0.05, 'pink':0.35, 'brown':0.22, 'blue':0.13}
y={'red':2, 'blue':3, 'yellow':1}
我的代碼不斷給我一個大字典的完整值列表。
for b in x.keys():
if b in y.keys():
k=y.values()
print k
output: [0.35, 0.22, 0.13, 0.05, 0.25]
Desired output:
[0.25,0.13,0.05]
有什麼建議嗎? 謝謝。
嗨@Sukrit,感謝很多的解決方案和解釋。我現在對這個問題有了更好的理解。 – Tiger1
@ Tiger1:很高興我的回答很有幫助。 :) –