Home>

Unable to sort new table by new column. Tried andsort(), andsorted(), andlambda– writes different errors all the time.

Source code:

data= [
    ['Grinning', 2.26, 1.02, 87.3],
    ['I beam with joy', 19.1, 1.69, 150.0],
    ['Riding with laughter', 25.6, 0.774, 0.0],
    ['Tears of Joy', 233.0, 7.31, 2270.0],
    ['Wink', 15.2, 2.36, 264.0],
    ['Happy', 22.7, 4.26, 565.0],
    ['Heart-eyes', 64.6, 11.2, 834.0],
    ['I kiss', 87.5, 5.13, 432.0],
    ['Thoughtful', 6.81, 0.636, 0.0],
    ['Indifference', 6.0, 0.236, 478.0],
    ['Sunglasses', 4.72, 3.93, 198.0],
    ['Crying Loudly', 24.7, 1.35, 654.0],
    ['Kiss Mark', 21.7, 2.87, 98.7],
    ['Two Hearts', 10.0, 5.69, 445.0],
    ['Heart', 118.0, 26.0, 1080.0],
    ['Hearts', 3.31, 1.82, 697.0],
    ['Class', 23.1, 3.75, 227.0],
    ['Shrug', 1.74, 0.11, 0.0],
    ['Fire', 4.5, 2.49, 150.0],
    ['Recycling', 0.0333, 0.056, 932.0]
]
print('Emoji name | Total usage, mln')
print('-----------------------------------------------------')
for i in data[:5]:
    sum= i[1] + i[2] + i[3]
    i.append(sum)
    print('{: <16} | {: >28.2f}'.format(i[0], i[4]))

Outputs:

Emoji name | Total use, mln
-----------------------------------------------------
grinning | 90.58
I beam with joy | 170.79
Rolling with laughter | 26.37
Tears of joy | 2510.31
wink | 281.56

Required to use onlysort(), but I tried a bunch of options, it did not work out and despaired.


PS From :
it is necessary to sort in descending order the values ​​of the "Total Usage" column from the table that the code displays.