我的python字典看起来像这样
{'1, ': (' name', '10G')}
{'2, ': (' name', '10G')}
{'3, ': (' name2', '40G')}
{'4, ': (' name2', '40G')}键为1到4,值为name*,*G
我想使用python得到的结果: 10G条目的数量=2,40G条目的数量=2
python代码是什么?
发布于 2016-11-22 14:18:20
您可以简单地使用Counter
>>> a = {
'1, ': (' name', '10G'),
'2, ': (' name', '10G'),
'3, ': (' name2', '40G'),
'4, ': (' name2', '40G')
}
>>> from collections import Counter
>>> c = Counter(a.values())
>>> c
Counter({(' name2', '40G'): 2, (' name', '10G'): 2})
>>> list(c.iteritems())
[((' name2', '40G'), 2), ((' name', '10G'), 2)]https://stackoverflow.com/questions/40734895
复制相似问题