如果键存在与否,我如何在二元字典中搜索键,如果存在则打印它的值?
wordsCounts = {('the','computer'): 2 , ('computer','science'): 3 , ('math','lecture'): 4, ('lecture','day'): 2}
所以,我想搜索这对是否('math','lecture')
存在?
pair = ['computer','science']
for k in wordscount.keys():
if wordscount[k] == pair:
print wordscount[v]
所以结果将是一个列表('computer','science'): 3