當前位置:成語大全網 - 新華字典 - python中如何統計兩個字典中相同單詞數量有多少個?

python中如何統計兩個字典中相同單詞數量有多少個?

>>> dictA={"a":1,"b":2,"c":3}

>>> dictB={"b":1,"c":2,"d":3}

>>> dict_temp={}

>>> for i in dictA:

dict_temp[i]=1

>>> for i in dictB:

dict_temp[i]=1

>>> duplicate_word_count=len(dictA)+len(dictB)-len(dict_temp)

>>> duplicate_word_count

2

>>>