I sorted lists within list on python. but I need to count list elements too. following list:
fruit = [
['Apple', 'S+'], ['Apple', 'S+'], ['Apple', 'B+'],
['Grape', 'B+'], ['Grape', 'C+']
]
result:
{'Apple':{'total':3, 'S+':2, 'B+':1}, 'Grape':{'total':2, 'B+':1, 'C+':1}}
I got above result through several for and while. but I want simple way. Is there beautiful and simple way to get result above thing ?