all_brands_scores = dict(sorted(all_brands_scores.items(), key=lambda item: item[1]))
print(all_brands_scores )
output:
{‘ADATA’: 0, ‘GIGABYTE’: 0, ‘CyberPowerPC’: 0, ‘Hyundai’: 0,
‘Thomson’: 0, ‘KANO’: 1, ‘Alienware’: 1, ‘Razer’: 1, ‘Google’: 1,
‘LG’: 2, ‘HP OMEN’: 5, ‘Acer’: 12, ‘Apple’: 13, ‘Microsoft’: 13,
‘MSI’: 17, ‘Samsung’: 18, ‘Dell’: 24, ‘ASUS’: 54, ‘Lenovo’: 71, ‘HP’:
104}
I have this file(dic) but not as fixed values
How do I calculate the percentage of each type of laptop ?
>Solution :
sum_of_values = sum(data.values())
dict(
map(
lambda v:
[
v[0],
str(v[1] / sum_of_values * 100) + "%"
],
data.items()
)
)