Sort a list numerically in Python

前端 未结 4 664
野性不改
野性不改 2021-01-23 03:27

So I have this list, we\'ll call it listA. I\'m trying to get the [3] item in each list e.g. [\'5.01\',\'5.88\',\'2.10\',\'9.45\',\'17.58\',\'2.76\'] in sorted orde

4条回答
  •  忘掉有多难
    2021-01-23 04:19

    Try this:

    >>> listA=[['John Doe', u'25.78', u'20.77', '5.01'], ['Jane Doe', u'21.08', u'15.20', '5.88'], ['James Bond', u'20.57', u'18.47', '2.10'], ['Michael Jordan', u'28.50', u'19.05', '9.45'], ['Santa', u'31.13', u'13.55', '17.58'], ['Easter Bunny', u'17.20', u'14.44', '2.76']]
    
    >>> [x[3] for x in sorted(listA, reverse = True, key = lambda i : float(i[3]))]
    ['17.58', '9.45', '5.88', '5.01', '2.76', '2.10']
    

提交回复
热议问题