我在python列表中对列表进行排序。但我也需要计算列表元素。下面的列表:如何统计python列表中的列表元素
fruit = [
['Apple', 'S+'], ['Apple', 'S+'], ['Apple', 'B+'],
['Grape', 'B+'], ['Grape', 'C+']
]
结果:
{'Apple':{'total':3, 'S+':2, 'B+':1}, 'Grape':{'total':2, 'B+':1, 'C+':1}}
我上面有导致通过几个并同时。但我想要简单的方法。有美丽和简单的方法来获得以上结果吗?