-1
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%')]
martineau
  • 119,623
  • 25
  • 170
  • 301
arun soman
  • 21
  • 8
  • Two things. Please add a [MCVE](http://stackoverflow.com/help/mcve) and secondly what is the question? – Jørgen Aug 29 '16 at 18:50
  • You are sorting *strings*, not numbers. So `'8'` comes before `'2'`; it doesn't matter that there is another character `'6'` after that `'2'`, that's not how textual sorting works. – Martijn Pieters Aug 29 '16 at 18:51

1 Answers1

0

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('%'))
Ouroborus
  • 16,237
  • 4
  • 39
  • 62