python如何把字典中所有內(nèi)容寫出來?
利用collections.counter可輕松辦到 >>> x = { 'apple': 1, 'banana': 2 } >>> y = { 'banana': 10, 'pear': 11 } >>> from collections import counter >>> x,y = counter(x), counter(y) >>> z = dict(x+y) >>> z 本人的寫法: >>>from collections import counter >>>dict(counter(x)+counter(y))