0

I have a list with 40 values in different formats like below:

line =['2005:450243780097359872', 'consumer', '(0, 0.038374472)', '(1, 0.038374227)', '(2, 0.46275997)', '(3, 0.03837424)', '(4, 0.038374268)', '(5, 0.038374446)', '(6, 0.038374227)', '(7, 0.038374294)', '(8, 0.03837436)', '(9, 0.038374227)', '(10, 0.038374227)', '(11, 0.03837425)', '(12, 0.038374335)', '(13, 0.038374227)', '(14, 0.038374227)', '(0, 0.038374472)', '(1, 0.038374227)', '(2, 0.46275997)', '(3, 0.03837424)', '(4, 0.038374268)', '(5, 0.038374446)', '(6, 0.038374227)', '(7, 0.038374294)', '(8, 0.03837436)', '(9, 0.038374227)', '(10, 0.038374227)', '(11, 0.03837425)', '(12, 0.038374335)', '(13, 0.038374227)', '(14, 0.038374227)', '355', '120', '110', '2014-03-30 12:10:56', '0', '0', 'consumer', '2005:450217727324856320']

I want to keep the second element of this list and also the tuple which has the biggest value of in terms of its second element. in short, I want this:

['consumer' , '(2, 0.46275997)']

this is the my code:

St = [line[1] , sorted(line[2:17] , reverse=True, key=lambda x:x[1])[0]]

and this is the result I get:

['consumer', '(9, 0.038374227)']

Can anybody explain why sorted() does not return what is expected? probably troubleshooting my code? Thanks

Pie-ton
  • 550
  • 4
  • 17

0 Answers0