fn = sorted(finalDataSet,key = lambda x : x[1],reverse=True)
I got a result like this:
[('Hyperelastic', '8%'), ('Orthotropic', '26%'), ('Plastic', '23%'),
('Composites', '17%'), ('Anisotropic', '13%'), ('Thermal', '13%')]
fn = sorted(finalDataSet,key = lambda x : x[1],reverse=True)
I got a result like this:
[('Hyperelastic', '8%'), ('Orthotropic', '26%'), ('Plastic', '23%'),
('Composites', '17%'), ('Anisotropic', '13%'), ('Thermal', '13%')]
It appears to be working correctly. You're sorting by strings and, alphabetically, '8%' is considered greater than '26%'. You may find this more useful as your lambda
:
lambda x : float(x[1].strip('%'))